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

Side by Side Diff: tests/lib/crypto/sha1_test.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/lib/crypto/hmac_sha256_test.dart ('k') | tests/lib/crypto/sha256_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 tag to allow dartium to run the test. 5 // Library tag to allow dartium to run the test.
6 library sha1_test; 6 library sha1_test;
7 7
8 import 'dart:crypto'; 8 import 'dart:crypto';
9 9
10 part 'sha1_long_test_vectors.dart'; 10 part 'sha1_long_test_vectors.dart';
11 part 'sha1_short_test_vectors.dart'; 11 part 'sha1_short_test_vectors.dart';
12 12
13 List<int> createTestArr(int len) { 13 List<int> createTestArr(int len) {
14 var arr = new List<int>(len); 14 var arr = new List<int>.fixedLength(len);
15 for (var i = 0; i < len; i++) { 15 for (var i = 0; i < len; i++) {
16 arr[i] = i; 16 arr[i] = i;
17 } 17 }
18 return arr; 18 return arr;
19 } 19 }
20 20
21 void test() { 21 void test() {
22 final expected_values = const [ 22 final expected_values = const [
23 "da39a3ee5e6b4b0d3255bfef95601890afd80709", 23 "da39a3ee5e6b4b0d3255bfef95601890afd80709",
24 "5ba93c9db0cff93f52b521d7420e43f6eda2784f", 24 "5ba93c9db0cff93f52b521d7420e43f6eda2784f",
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 "d64a178d4759b796ec0e77626cf19257c28292fc", 527 "d64a178d4759b796ec0e77626cf19257c28292fc",
528 "6ae457f71b1cd60b1810fd4379c90bb38154568f", 528 "6ae457f71b1cd60b1810fd4379c90bb38154568f",
529 "063623280f208df296895ccd867dab8a73cf174d", 529 "063623280f208df296895ccd867dab8a73cf174d",
530 "7a8b8c9aa0591603cf08e94ec2ae6a6350cbb8a2", 530 "7a8b8c9aa0591603cf08e94ec2ae6a6350cbb8a2",
531 "20c4232d3066c41e211eefe2834db78a8c083ea4", 531 "20c4232d3066c41e211eefe2834db78a8c083ea4",
532 "82fdf2cccc77ab556aa35557d0923b162d1b98cf", 532 "82fdf2cccc77ab556aa35557d0923b162d1b98cf",
533 "3dce8306f3c1810d5d81ed5ebb0ccea947277a61", 533 "3dce8306f3c1810d5d81ed5ebb0ccea947277a61",
534 "11bca5b61fc1f6d59078ec5354bc6d9adecc0c5d", 534 "11bca5b61fc1f6d59078ec5354bc6d9adecc0c5d",
535 ]; 535 ];
536 for (var i = 0; i < expected_values.length; i++) { 536 for (var i = 0; i < expected_values.length; i++) {
537 var digest = new SHA1().update(createTestArr(i)).digest(); 537 var hash = new SHA1();
538 hash.add(createTestArr(i));
539 var digest = hash.close();
538 Expect.equals(expected_values[i], CryptoUtils.bytesToHex(digest)); 540 Expect.equals(expected_values[i], CryptoUtils.bytesToHex(digest));
539 } 541 }
540 } 542 }
541 543
542 void testInvalidUse() { 544 void testInvalidUse() {
543 var sha = new SHA1(); 545 var sha = new SHA1();
544 sha.digest(); 546 sha.close();
545 Expect.throws(() => sha.update([0]), (e) => e is HashException); 547 Expect.throws(() => sha.add([0]), (e) => e is HashException);
546 } 548 }
547 549
548 void testRepeatedDigest() { 550 void testRepeatedDigest() {
549 var sha = new SHA1(); 551 var sha = new SHA1();
550 var digest = sha.digest(); 552 var digest = sha.close();
551 Expect.listEquals(digest, sha.digest()); 553 Expect.listEquals(digest, sha.close());
552 } 554 }
553 555
554 void testStandardVectors(inputs, mds) { 556 void testStandardVectors(inputs, mds) {
555 for (var i = 0; i < inputs.length; i++) { 557 for (var i = 0; i < inputs.length; i++) {
556 var d = new SHA1().update(inputs[i]).digest(); 558 var hash = new SHA1();
559 hash.add(inputs[i]);
560 var d = hash.close();
557 Expect.equals(mds[i], CryptoUtils.bytesToHex(d), '$i'); 561 Expect.equals(mds[i], CryptoUtils.bytesToHex(d), '$i');
558 } 562 }
559 } 563 }
560 564
561 void main() { 565 void main() {
562 test(); 566 test();
563 testInvalidUse(); 567 testInvalidUse();
564 testRepeatedDigest(); 568 testRepeatedDigest();
565 testStandardVectors(sha1_long_inputs, sha1_long_mds); 569 testStandardVectors(sha1_long_inputs, sha1_long_mds);
566 testStandardVectors(sha1_short_inputs, sha1_short_mds); 570 testStandardVectors(sha1_short_inputs, sha1_short_mds);
567 } 571 }
OLDNEW
« no previous file with comments | « tests/lib/crypto/hmac_sha256_test.dart ('k') | tests/lib/crypto/sha256_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698