| 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'); |
| 9 #source('sha1_short_test_vectors.dart'); |
| 10 |
| 8 List<int> createTestArr(int len) { | 11 List<int> createTestArr(int len) { |
| 9 var arr = new List<int>(len); | 12 var arr = new List<int>(len); |
| 10 for (var i = 0; i < len; i++) { | 13 for (var i = 0; i < len; i++) { |
| 11 arr[i] = i; | 14 arr[i] = i; |
| 12 } | 15 } |
| 13 return arr; | 16 return arr; |
| 14 } | 17 } |
| 15 | 18 |
| 16 String digestToString(List<int> digest) { | 19 String digestToString(List<int> digest) { |
| 17 var buf = new StringBuffer(); | 20 var buf = new StringBuffer(); |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 | 547 |
| 545 void testInvalidUse() { | 548 void testInvalidUse() { |
| 546 var sha = new SHA1(); | 549 var sha = new SHA1(); |
| 547 sha.digest(); | 550 sha.digest(); |
| 548 Expect.throws(sha.digest, | 551 Expect.throws(sha.digest, |
| 549 (e) => e is CryptoHashException); | 552 (e) => e is CryptoHashException); |
| 550 Expect.throws(() => sha.update([0]), | 553 Expect.throws(() => sha.update([0]), |
| 551 (e) => e is CryptoHashException); | 554 (e) => e is CryptoHashException); |
| 552 } | 555 } |
| 553 | 556 |
| 557 void testStandardVectors(inputs, mds) { |
| 558 for (var i = 0; i < inputs.length; i++) { |
| 559 var d = new SHA1().update(inputs[i]).digest(); |
| 560 Expect.equals(mds[i], digestToString(d), '$i'); |
| 561 } |
| 562 } |
| 563 |
| 554 void main() { | 564 void main() { |
| 555 test(); | 565 test(); |
| 556 testInvalidUse(); | 566 testInvalidUse(); |
| 567 testStandardVectors(sha1_long_inputs, sha1_long_mds); |
| 568 testStandardVectors(sha1_short_inputs, sha1_short_mds); |
| 557 } | 569 } |
| OLD | NEW |