Chromium Code Reviews| Index: lib/crypto/crypto.dart |
| diff --git a/lib/crypto/crypto.dart b/lib/crypto/crypto.dart |
| index 6a839974017206c69f7f1bc73cea24a0209bca80..6b2c9f32d86779d1c75b43ccd6536d2eed06d6db 100644 |
| --- a/lib/crypto/crypto.dart |
| +++ b/lib/crypto/crypto.dart |
| @@ -4,6 +4,7 @@ |
| #library('crypto'); |
| +#source('hmac.dart'); |
| #source('sha_utils.dart'); |
| #source('sha1.dart'); |
| #source('sha256.dart'); |
| @@ -12,10 +13,14 @@ |
| * Interface for cryptographic hash functions. |
| * |
| * The [update] method is used to add data to the hash. The [digest] method |
| - * is used to extract the message digest. Once the [digest] method has been |
| - * called the CryptoHash object is in an invalid state and should not be |
| - * used again. If [digest] or [update] are called after the first call to |
| - * [digest] a CryptoHashException is thrown. |
| + * is used to extract the message digest. |
| + * |
| + * Once the [digest] method has been called the CryptoHash object is in an |
| + * invalid state and should not be used again. If [digest] or [update] are |
| + * 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
|
| + * |
| + * If multiple instances of a given CryptoHash is needed the [newInstance] |
| + * method can provide a new instance. |
| */ |
| interface CryptoHash { |
| /** |
| @@ -28,6 +33,16 @@ interface CryptoHash { |
| * a list of bytes. |
| */ |
| List<int> digest(); |
| + |
| + /** |
| + * Returns a new instance of this hash function. |
| + */ |
| + CryptoHash newInstance(); |
| + |
| + /** |
| + * Block size of the hash in bytes. |
| + */ |
| + int get blockSize(); |
| } |
| /** |
| @@ -46,6 +61,31 @@ interface SHA256 extends CryptoHash default _SHA256 { |
| /** |
| + * Hash-based Message Authentication Code support. |
| + * |
| + * The [update] method is used to add data to the message. The [digest] method |
| + * is used to extract the message authentication code. |
| + */ |
| +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
|
| + /** |
| + * Create an [HMAC] object from a [CryptoHash] and a key. |
| + */ |
| + HMAC(CryptoHash hash, List<int> key); |
| + |
| + /** |
| + * Add a list of bytes to the message. |
| + */ |
| + HMAC update(List<int> data); |
| + |
| + /** |
| + * Perform the actual computation and extract the message digest |
| + * as a list of bytes. |
| + */ |
| + List<int> digest(); |
| +} |
| + |
| + |
| +/** |
| * CryptoHashExceptions are thrown on invalid use of a CryptoHash |
| * object. |
| */ |