Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #library('crypto'); | 5 #library('crypto'); |
| 6 | 6 |
| 7 #source('crypto_utils.dart'); | |
| 7 #source('hmac.dart'); | 8 #source('hmac.dart'); |
| 8 #source('sha_utils.dart'); | 9 #source('sha_utils.dart'); |
| 9 #source('sha1.dart'); | 10 #source('sha1.dart'); |
| 10 #source('sha256.dart'); | 11 #source('sha256.dart'); |
| 11 | 12 |
| 12 /** | 13 /** |
| 13 * Interface for cryptographic hash functions. | 14 * Interface for cryptographic hash functions. |
| 14 * | 15 * |
| 15 * The [update] method is used to add data to the hash. The [digest] method | 16 * The [update] method is used to add data to the hash. The [digest] method |
| 16 * is used to extract the message digest. | 17 * is used to extract the message digest. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 SHA1(); | 53 SHA1(); |
| 53 } | 54 } |
| 54 | 55 |
| 55 /** | 56 /** |
| 56 * SHA256 hash function implementation. | 57 * SHA256 hash function implementation. |
| 57 */ | 58 */ |
| 58 interface SHA256 extends Hash default _SHA256 { | 59 interface SHA256 extends Hash default _SHA256 { |
| 59 SHA256(); | 60 SHA256(); |
| 60 } | 61 } |
| 61 | 62 |
| 62 | |
| 63 /** | 63 /** |
| 64 * Hash-based Message Authentication Code support. | 64 * Hash-based Message Authentication Code support. |
| 65 * | 65 * |
| 66 * The [update] method is used to add data to the message. The [digest] method | 66 * The [update] method is used to add data to the message. The [digest] method |
| 67 * is used to extract the message authentication code. | 67 * is used to extract the message authentication code. |
| 68 */ | 68 */ |
| 69 interface HMAC default _HMAC { | 69 interface HMAC default _HMAC { |
| 70 /** | 70 /** |
| 71 * Create an [HMAC] object from a [Hash] and a key. | 71 * Create an [HMAC] object from a [Hash] and a key. |
| 72 */ | 72 */ |
| 73 HMAC(Hash hash, List<int> key); | 73 HMAC(Hash hash, List<int> key); |
| 74 | 74 |
| 75 /** | 75 /** |
| 76 * Add a list of bytes to the message. | 76 * Add a list of bytes to the message. |
| 77 */ | 77 */ |
| 78 HMAC update(List<int> data); | 78 HMAC update(List<int> data); |
| 79 | 79 |
| 80 /** | 80 /** |
| 81 * Perform the actual computation and extract the message digest | 81 * Perform the actual computation and extract the message digest |
| 82 * as a list of bytes. | 82 * as a list of bytes. |
| 83 */ | 83 */ |
| 84 List<int> digest(); | 84 List<int> digest(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 /** | |
| 88 * Utility methods for working with message digests. | |
| 89 */ | |
| 90 class CryptoUtils { | |
| 91 /** | |
| 92 * Convert a message digest which is a list of bytes into a hex | |
| 93 * string. | |
| 94 */ | |
| 95 static String digestToHex(List<int> digest) { | |
|
Søren Gjesse
2012/05/07 14:26:34
Shouldn't this just be bytesToHex? This can be use
Mads Ager (google)
2012/05/07 14:34:59
Good point. Done.
| |
| 96 return _CryptoUtils.digestToHex(digest); | |
| 97 } | |
| 98 } | |
| 87 | 99 |
| 88 /** | 100 /** |
| 89 * HashExceptions are thrown on invalid use of a Hash | 101 * HashExceptions are thrown on invalid use of a Hash |
| 90 * object. | 102 * object. |
| 91 */ | 103 */ |
| 92 class HashException { | 104 class HashException { |
| 93 HashException(String this.message); | 105 HashException(String this.message); |
| 94 toString() => "HashException: $message"; | 106 toString() => "HashException: $message"; |
| 95 String message; | 107 String message; |
| 96 } | 108 } |
| 97 | 109 |
| OLD | NEW |