Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "package:expect/expect.dart"; | |
| 9 import "package:crypto/crypto.dart"; | 8 import "package:crypto/crypto.dart"; |
| 9 import "package:unittest/unittest.dart"; | |
| 10 | 10 |
| 11 part 'sha1_long_test_vectors.dart'; | 11 part 'sha1_long_test_vectors.dart'; |
| 12 part 'sha1_short_test_vectors.dart'; | 12 part 'sha1_short_test_vectors.dart'; |
| 13 | 13 |
| 14 List<int> createTestArr(int len) { | 14 |
| 15 var arr = new List<int>(len); | 15 void main() { |
| 16 for (var i = 0; i < len; i++) { | 16 test('expected values', _testExpectedValues); |
| 17 arr[i] = i; | 17 test('invalid use', _testInvalidUse); |
| 18 } | 18 test('repeated digest', _testRepeatedDigest); |
| 19 return arr; | 19 test('long inputs', () { |
| 20 _testStandardVectors(sha1_long_inputs, sha1_long_mds); | |
| 21 }); | |
| 22 test('short inputs', () { | |
| 23 _testStandardVectors(sha1_short_inputs, sha1_short_mds); | |
| 24 }); | |
| 20 } | 25 } |
| 21 | 26 |
| 22 void test() { | 27 void _testExpectedValues() { |
| 23 final expected_values = const [ | 28 final expected_values = const [ |
|
Søren Gjesse
2014/02/18 07:41:38
expected_values -> expectedValues
kevmoo
2014/02/18 14:23:27
Done.
| |
| 24 "da39a3ee5e6b4b0d3255bfef95601890afd80709", | 29 "da39a3ee5e6b4b0d3255bfef95601890afd80709", |
| 25 "5ba93c9db0cff93f52b521d7420e43f6eda2784f", | 30 "5ba93c9db0cff93f52b521d7420e43f6eda2784f", |
| 26 "3f29546453678b855931c174a97d6c0894b8f546", | 31 "3f29546453678b855931c174a97d6c0894b8f546", |
| 27 "0c7a623fd2bbc05b06423be359e4021d36e721ad", | 32 "0c7a623fd2bbc05b06423be359e4021d36e721ad", |
| 28 "a02a05b025b928c039cf1ae7e8ee04e7c190c0db", | 33 "a02a05b025b928c039cf1ae7e8ee04e7c190c0db", |
| 29 "1cf251472d59f8fadeb3ab258e90999d8491be19", | 34 "1cf251472d59f8fadeb3ab258e90999d8491be19", |
| 30 "868460d98d09d8bbb93d7b6cdd15cc7fbec676b9", | 35 "868460d98d09d8bbb93d7b6cdd15cc7fbec676b9", |
| 31 "6dc86f11b8cdbe879bf8ba3832499c2f93c729ba", | 36 "6dc86f11b8cdbe879bf8ba3832499c2f93c729ba", |
| 32 "67423ebfa8454f19ac6f4686d6c0dc731a3ddd6b", | 37 "67423ebfa8454f19ac6f4686d6c0dc731a3ddd6b", |
| 33 "63bf60c7105a07a2b125bbf89e61abdabc6978c2", | 38 "63bf60c7105a07a2b125bbf89e61abdabc6978c2", |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 529 "6ae457f71b1cd60b1810fd4379c90bb38154568f", | 534 "6ae457f71b1cd60b1810fd4379c90bb38154568f", |
| 530 "063623280f208df296895ccd867dab8a73cf174d", | 535 "063623280f208df296895ccd867dab8a73cf174d", |
| 531 "7a8b8c9aa0591603cf08e94ec2ae6a6350cbb8a2", | 536 "7a8b8c9aa0591603cf08e94ec2ae6a6350cbb8a2", |
| 532 "20c4232d3066c41e211eefe2834db78a8c083ea4", | 537 "20c4232d3066c41e211eefe2834db78a8c083ea4", |
| 533 "82fdf2cccc77ab556aa35557d0923b162d1b98cf", | 538 "82fdf2cccc77ab556aa35557d0923b162d1b98cf", |
| 534 "3dce8306f3c1810d5d81ed5ebb0ccea947277a61", | 539 "3dce8306f3c1810d5d81ed5ebb0ccea947277a61", |
| 535 "11bca5b61fc1f6d59078ec5354bc6d9adecc0c5d", | 540 "11bca5b61fc1f6d59078ec5354bc6d9adecc0c5d", |
| 536 ]; | 541 ]; |
| 537 for (var i = 0; i < expected_values.length; i++) { | 542 for (var i = 0; i < expected_values.length; i++) { |
| 538 var hash = new SHA1(); | 543 var hash = new SHA1(); |
| 539 hash.add(createTestArr(i)); | 544 hash.add(new List<int>.generate(i, (j) => j, growable: false)); |
| 540 var digest = hash.close(); | 545 var digest = hash.close(); |
| 541 Expect.equals(expected_values[i], CryptoUtils.bytesToHex(digest)); | 546 expect(expected_values[i], CryptoUtils.bytesToHex(digest)); |
| 542 } | 547 } |
| 543 } | 548 } |
| 544 | 549 |
| 545 void testInvalidUse() { | 550 void _testInvalidUse() { |
| 546 var sha = new SHA1(); | 551 var sha = new SHA1(); |
| 547 sha.close(); | 552 sha.close(); |
| 548 Expect.throws(() => sha.add([0]), (e) => e is StateError); | 553 expect(() => sha.add([0]), throwsStateError); |
| 549 } | 554 } |
| 550 | 555 |
| 551 void testRepeatedDigest() { | 556 void _testRepeatedDigest() { |
| 552 var sha = new SHA1(); | 557 var sha = new SHA1(); |
| 553 var digest = sha.close(); | 558 var digest = sha.close(); |
| 554 Expect.listEquals(digest, sha.close()); | 559 expect(digest, sha.close()); |
| 555 } | 560 } |
| 556 | 561 |
| 557 void testStandardVectors(inputs, mds) { | 562 void _testStandardVectors(inputs, mds) { |
| 558 for (var i = 0; i < inputs.length; i++) { | 563 for (var i = 0; i < inputs.length; i++) { |
| 559 var hash = new SHA1(); | 564 var hash = new SHA1(); |
| 560 hash.add(inputs[i]); | 565 hash.add(inputs[i]); |
| 561 var d = hash.close(); | 566 var d = hash.close(); |
| 562 Expect.equals(mds[i], CryptoUtils.bytesToHex(d), '$i'); | 567 expect(mds[i], CryptoUtils.bytesToHex(d), reason: '$i'); |
| 563 } | 568 } |
| 564 } | 569 } |
| 565 | |
| 566 void main() { | |
| 567 test(); | |
| 568 testInvalidUse(); | |
| 569 testRepeatedDigest(); | |
| 570 testStandardVectors(sha1_long_inputs, sha1_long_mds); | |
| 571 testStandardVectors(sha1_short_inputs, sha1_short_mds); | |
| 572 } | |
| OLD | NEW |