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('hmac.dart'); | |
| 7 #source('sha_utils.dart'); | 8 #source('sha_utils.dart'); |
| 8 #source('sha1.dart'); | 9 #source('sha1.dart'); |
| 9 #source('sha256.dart'); | 10 #source('sha256.dart'); |
| 10 | 11 |
| 11 /** | 12 /** |
| 12 * Interface for cryptographic hash functions. | 13 * Interface for cryptographic hash functions. |
| 13 * | 14 * |
| 14 * The [update] method is used to add data to the hash. The [digest] method | 15 * The [update] method is used to add data to the hash. The [digest] method |
| 15 * is used to extract the message digest. Once the [digest] method has been | 16 * is used to extract the message digest. |
| 16 * called the CryptoHash object is in an invalid state and should not be | 17 * |
| 17 * used again. If [digest] or [update] are called after the first call to | 18 * Once the [digest] method has been called the CryptoHash object is in an |
| 18 * [digest] a CryptoHashException is thrown. | 19 * invalid state and should not be used again. If [digest] or [update] are |
| 20 * called after the first call to [digest] a CryptoHashException is thrown. | |
|
Ben Laurie (Google)
2012/04/27 13:26:33
I still say you should be able to call [digest] a
Mads Ager (google)
2012/04/30 07:56:57
OK, allowed multiple calls to digest to extract th
| |
| 21 * | |
| 22 * If multiple instances of a given CryptoHash is needed the [newInstance] | |
| 23 * method can provide a new instance. | |
| 19 */ | 24 */ |
| 20 interface CryptoHash { | 25 interface CryptoHash { |
| 21 /** | 26 /** |
| 22 * Add a list of bytes to the hash computation. | 27 * Add a list of bytes to the hash computation. |
| 23 */ | 28 */ |
| 24 CryptoHash update(List<int> data); | 29 CryptoHash update(List<int> data); |
| 25 | 30 |
| 26 /** | 31 /** |
| 27 * Finish the hash computation and extract the message digest as | 32 * Finish the hash computation and extract the message digest as |
| 28 * a list of bytes. | 33 * a list of bytes. |
| 29 */ | 34 */ |
| 30 List<int> digest(); | 35 List<int> digest(); |
| 36 | |
| 37 /** | |
| 38 * Returns a new instance of this hash function. | |
| 39 */ | |
| 40 CryptoHash newInstance(); | |
| 41 | |
| 42 /** | |
| 43 * Block size of the hash in bytes. | |
| 44 */ | |
| 45 int get blockSize(); | |
| 31 } | 46 } |
| 32 | 47 |
| 33 /** | 48 /** |
| 34 * SHA1 hash function implementation. | 49 * SHA1 hash function implementation. |
| 35 */ | 50 */ |
| 36 interface SHA1 extends CryptoHash default _SHA1 { | 51 interface SHA1 extends CryptoHash default _SHA1 { |
| 37 SHA1(); | 52 SHA1(); |
| 38 } | 53 } |
| 39 | 54 |
| 40 /** | 55 /** |
| 41 * SHA256 hash function implementation. | 56 * SHA256 hash function implementation. |
| 42 */ | 57 */ |
| 43 interface SHA256 extends CryptoHash default _SHA256 { | 58 interface SHA256 extends CryptoHash default _SHA256 { |
| 44 SHA256(); | 59 SHA256(); |
| 45 } | 60 } |
| 46 | 61 |
| 47 | 62 |
| 48 /** | 63 /** |
| 64 * Hash-based Message Authentication Code support. | |
| 65 * | |
| 66 * The [update] method is used to add data to the message. The [digest] method | |
| 67 * is used to extract the message authentication code. | |
| 68 */ | |
| 69 interface HMAC default _HMAC { | |
|
Ben Laurie (Google)
2012/04/27 13:26:33
Why CryptoHash and not CryptoHMAC?
Mads Ager (google)
2012/04/30 07:56:57
Yeah, good question. There is next to zero chance
| |
| 70 /** | |
| 71 * Create an [HMAC] object from a [CryptoHash] and a key. | |
| 72 */ | |
| 73 HMAC(CryptoHash hash, List<int> key); | |
| 74 | |
| 75 /** | |
| 76 * Add a list of bytes to the message. | |
| 77 */ | |
| 78 HMAC update(List<int> data); | |
| 79 | |
| 80 /** | |
| 81 * Perform the actual computation and extract the message digest | |
| 82 * as a list of bytes. | |
| 83 */ | |
| 84 List<int> digest(); | |
| 85 } | |
| 86 | |
| 87 | |
| 88 /** | |
| 49 * CryptoHashExceptions are thrown on invalid use of a CryptoHash | 89 * CryptoHashExceptions are thrown on invalid use of a CryptoHash |
| 50 * object. | 90 * object. |
| 51 */ | 91 */ |
| 52 class CryptoHashException { | 92 class CryptoHashException { |
| 53 CryptoHashException(String this.message); | 93 CryptoHashException(String this.message); |
| 54 toString() => "CryptoHashException: $message"; | 94 toString() => "CryptoHashException: $message"; |
| 55 String message; | 95 String message; |
| 56 } | 96 } |
| 57 | 97 |
| OLD | NEW |