Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(740)

Unified Diff: pkg/crypto/lib/src/hmac.dart

Issue 16624003: Remove the crypto factories (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/crypto/lib/crypto.dart ('k') | pkg/crypto/lib/src/md5.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/crypto/lib/src/hmac.dart
diff --git a/pkg/crypto/lib/src/hmac.dart b/pkg/crypto/lib/src/hmac.dart
index 2d07cff9a152502d1ecbd755c6c8fea4ab24a095..59c177109497d52a6319baa2a60f81765d628a0b 100644
--- a/pkg/crypto/lib/src/hmac.dart
+++ b/pkg/crypto/lib/src/hmac.dart
@@ -4,16 +4,32 @@
part of crypto;
-class _HMAC implements HMAC {
+/**
+ * Hash-based Message Authentication Code support.
+ *
+ * The [add] method is used to add data to the message. The [digest] and
+ * [close] methods are used to extract the message authentication code.
+ */
+// TODO(floitsch): make Hash implement Sink, EventSink or similar.
+class HMAC {
bool _isClosed = false;
- _HMAC(Hash this._hash, List<int> this._key) : _message = [];
+ /**
+ * Create an [HMAC] object from a [Hash] and a key.
+ */
+ HMAC(Hash this._hash, List<int> this._key) : _message = [];
+ /**
+ * Add a list of bytes to the message.
+ */
add(List<int> data) {
if (_isClosed) throw new StateError("HMAC is closed");
_message.addAll(data);
}
+ /**
+ * Extract the message digest as a list of bytes without closing [this].
+ */
List<int> get digest {
var blockSize = _hash.blockSize;
@@ -58,11 +74,25 @@ class _HMAC implements HMAC {
return _hash.close();
}
+ /**
+ * Perform the actual computation and extract the message digest
+ * as a list of bytes.
+ */
List<int> close() {
_isClosed = true;
return digest;
}
+ /**
+ * Verify that the HMAC computed for the data so far matches the
+ * given message digest.
+ *
+ * This method should be used instead of memcmp-style comparisons
+ * to avoid leaking information via timing.
+ *
+ * Throws an exception if the given digest does not have the same
+ * size as the digest computed by this HMAC instance.
+ */
bool verify(List<int> digest) {
var computedDigest = this.digest;
if (digest.length != computedDigest.length) {
« no previous file with comments | « pkg/crypto/lib/crypto.dart ('k') | pkg/crypto/lib/src/md5.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698