| 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 // TODO(ager): Replace with "dart:crypto" when ready. | 5 // TODO(ager): Replace with "dart:crypto" when ready. |
| 6 #import("../../../../lib/crypto/crypto.dart"); | 6 #import("../../../../lib/crypto/crypto.dart"); |
| 7 | 7 |
| 8 #source('sha1_long_test_vectors.dart'); | 8 #source('sha1_long_test_vectors.dart'); |
| 9 #source('sha1_short_test_vectors.dart'); | 9 #source('sha1_short_test_vectors.dart'); |
| 10 | 10 |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 ]; | 541 ]; |
| 542 for (var i = 0; i < expected_values.length; i++) { | 542 for (var i = 0; i < expected_values.length; i++) { |
| 543 Expect.equals(expected_values[i], | 543 Expect.equals(expected_values[i], |
| 544 digestToString(new SHA1().update(createTestArr(i)).digest())); | 544 digestToString(new SHA1().update(createTestArr(i)).digest())); |
| 545 } | 545 } |
| 546 } | 546 } |
| 547 | 547 |
| 548 void testInvalidUse() { | 548 void testInvalidUse() { |
| 549 var sha = new SHA1(); | 549 var sha = new SHA1(); |
| 550 sha.digest(); | 550 sha.digest(); |
| 551 Expect.throws(sha.digest, | 551 Expect.throws(() => sha.update([0]), (e) => e is HashException); |
| 552 (e) => e is CryptoHashException); | 552 } |
| 553 Expect.throws(() => sha.update([0]), | 553 |
| 554 (e) => e is CryptoHashException); | 554 void testRepeatedDigest() { |
| 555 var sha = new SHA1(); |
| 556 var digest = sha.digest(); |
| 557 Expect.listEquals(digest, sha.digest()); |
| 555 } | 558 } |
| 556 | 559 |
| 557 void testStandardVectors(inputs, mds) { | 560 void testStandardVectors(inputs, mds) { |
| 558 for (var i = 0; i < inputs.length; i++) { | 561 for (var i = 0; i < inputs.length; i++) { |
| 559 var d = new SHA1().update(inputs[i]).digest(); | 562 var d = new SHA1().update(inputs[i]).digest(); |
| 560 Expect.equals(mds[i], digestToString(d), '$i'); | 563 Expect.equals(mds[i], digestToString(d), '$i'); |
| 561 } | 564 } |
| 562 } | 565 } |
| 563 | 566 |
| 564 void main() { | 567 void main() { |
| 565 test(); | 568 test(); |
| 566 testInvalidUse(); | 569 testInvalidUse(); |
| 570 testRepeatedDigest(); |
| 567 testStandardVectors(sha1_long_inputs, sha1_long_mds); | 571 testStandardVectors(sha1_long_inputs, sha1_long_mds); |
| 568 testStandardVectors(sha1_short_inputs, sha1_short_mds); | 572 testStandardVectors(sha1_short_inputs, sha1_short_mds); |
| 569 } | 573 } |
| OLD | NEW |