| Index: lib/crypto/crypto.dart
|
| diff --git a/lib/crypto/crypto.dart b/lib/crypto/crypto.dart
|
| index 6a839974017206c69f7f1bc73cea24a0209bca80..f17c0f0e9c9c9d79aae83e3357eca9d592f381ae 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,46 +13,85 @@
|
| * 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 no more data can be added using the
|
| + * [update] method. If [update] is called after the first call to [digest] a
|
| + * HashException is thrown.
|
| + *
|
| + * If multiple instances of a given Hash is needed the [newInstance]
|
| + * method can provide a new instance.
|
| */
|
| -interface CryptoHash {
|
| +interface Hash {
|
| /**
|
| * Add a list of bytes to the hash computation.
|
| */
|
| - CryptoHash update(List<int> data);
|
| + Hash update(List<int> data);
|
|
|
| /**
|
| * Finish the hash computation and extract the message digest as
|
| * a list of bytes.
|
| */
|
| List<int> digest();
|
| +
|
| + /**
|
| + * Returns a new instance of this hash function.
|
| + */
|
| + Hash newInstance();
|
| +
|
| + /**
|
| + * Block size of the hash in bytes.
|
| + */
|
| + int get blockSize();
|
| }
|
|
|
| /**
|
| * SHA1 hash function implementation.
|
| */
|
| -interface SHA1 extends CryptoHash default _SHA1 {
|
| +interface SHA1 extends Hash default _SHA1 {
|
| SHA1();
|
| }
|
|
|
| /**
|
| * SHA256 hash function implementation.
|
| */
|
| -interface SHA256 extends CryptoHash default _SHA256 {
|
| +interface SHA256 extends Hash default _SHA256 {
|
| SHA256();
|
| }
|
|
|
|
|
| /**
|
| - * CryptoHashExceptions are thrown on invalid use of a CryptoHash
|
| + * 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 {
|
| + /**
|
| + * Create an [HMAC] object from a [Hash] and a key.
|
| + */
|
| + HMAC(Hash 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();
|
| +}
|
| +
|
| +
|
| +/**
|
| + * HashExceptions are thrown on invalid use of a Hash
|
| * object.
|
| */
|
| -class CryptoHashException {
|
| - CryptoHashException(String this.message);
|
| - toString() => "CryptoHashException: $message";
|
| +class HashException {
|
| + HashException(String this.message);
|
| + toString() => "HashException: $message";
|
| String message;
|
| }
|
|
|
|
|