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