| 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"; | 8 import "package:expect/expect.dart"; |
| 9 import "package:crypto/crypto.dart"; | 9 import "package:crypto/crypto.dart"; |
| 10 | 10 |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 var hash = new SHA1(); | 538 var hash = new SHA1(); |
| 539 hash.add(createTestArr(i)); | 539 hash.add(createTestArr(i)); |
| 540 var digest = hash.close(); | 540 var digest = hash.close(); |
| 541 Expect.equals(expected_values[i], CryptoUtils.bytesToHex(digest)); | 541 Expect.equals(expected_values[i], CryptoUtils.bytesToHex(digest)); |
| 542 } | 542 } |
| 543 } | 543 } |
| 544 | 544 |
| 545 void testInvalidUse() { | 545 void testInvalidUse() { |
| 546 var sha = new SHA1(); | 546 var sha = new SHA1(); |
| 547 sha.close(); | 547 sha.close(); |
| 548 Expect.throws(() => sha.add([0]), (e) => e is HashException); | 548 Expect.throws(() => sha.add([0]), (e) => e is StateError); |
| 549 } | 549 } |
| 550 | 550 |
| 551 void testRepeatedDigest() { | 551 void testRepeatedDigest() { |
| 552 var sha = new SHA1(); | 552 var sha = new SHA1(); |
| 553 var digest = sha.close(); | 553 var digest = sha.close(); |
| 554 Expect.listEquals(digest, sha.close()); | 554 Expect.listEquals(digest, sha.close()); |
| 555 } | 555 } |
| 556 | 556 |
| 557 void testStandardVectors(inputs, mds) { | 557 void testStandardVectors(inputs, mds) { |
| 558 for (var i = 0; i < inputs.length; i++) { | 558 for (var i = 0; i < inputs.length; i++) { |
| 559 var hash = new SHA1(); | 559 var hash = new SHA1(); |
| 560 hash.add(inputs[i]); | 560 hash.add(inputs[i]); |
| 561 var d = hash.close(); | 561 var d = hash.close(); |
| 562 Expect.equals(mds[i], CryptoUtils.bytesToHex(d), '$i'); | 562 Expect.equals(mds[i], CryptoUtils.bytesToHex(d), '$i'); |
| 563 } | 563 } |
| 564 } | 564 } |
| 565 | 565 |
| 566 void main() { | 566 void main() { |
| 567 test(); | 567 test(); |
| 568 testInvalidUse(); | 568 testInvalidUse(); |
| 569 testRepeatedDigest(); | 569 testRepeatedDigest(); |
| 570 testStandardVectors(sha1_long_inputs, sha1_long_mds); | 570 testStandardVectors(sha1_long_inputs, sha1_long_mds); |
| 571 testStandardVectors(sha1_short_inputs, sha1_short_mds); | 571 testStandardVectors(sha1_short_inputs, sha1_short_mds); |
| 572 } | 572 } |
| OLD | NEW |