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

Unified Diff: tests/lib/crypto/hmac_sha256_test.dart

Issue 10170027: Implement HMAC support in lib/crypto. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update after test renaming. Added back lib testing in test.dart." Created 8 years, 8 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 | « tests/lib/crypto/hmac_sha1_test_vectors.dart ('k') | tests/lib/crypto/hmac_sha256_test_vectors.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/crypto/hmac_sha256_test.dart
diff --git a/tests/lib/crypto/hmac_sha256_test.dart b/tests/lib/crypto/hmac_sha256_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..59aa65609304922d0cc3345d0c575148fbbe6667
--- /dev/null
+++ b/tests/lib/crypto/hmac_sha256_test.dart
@@ -0,0 +1,27 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// TODO(ager): Replace with "dart:crypto" when ready.
+#import("../../../lib/crypto/crypto.dart");
+
+#source('hmac_sha256_test_vectors.dart');
+
+String digestToString(List<int> digest) {
+ var buf = new StringBuffer();
+ for (var part in digest) {
+ buf.add("${(part < 16) ? "0" : ""}${part.toRadixString(16).toLowerCase()}");
+ }
+ return buf.toString();
+}
+
+void testStandardVectors(inputs, keys, macs) {
+ for (var i = 0; i < inputs.length; i++) {
+ var d = new HMAC(new SHA256(), keys[i]).update(inputs[i]).digest();
+ Expect.isTrue(digestToString(d).startsWith(macs[i]), '$i');
+ }
+}
+
+void main() {
+ testStandardVectors(hmac_sha256_inputs, hmac_sha256_keys, hmac_sha256_macs);
+}
« no previous file with comments | « tests/lib/crypto/hmac_sha1_test_vectors.dart ('k') | tests/lib/crypto/hmac_sha256_test_vectors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698