| 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('sha256_long_test_vectors.dart'); |
| 9 #source('sha256_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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 | 291 |
| 289 void testInvalidUse() { | 292 void testInvalidUse() { |
| 290 var sha = new SHA256(); | 293 var sha = new SHA256(); |
| 291 sha.digest(); | 294 sha.digest(); |
| 292 Expect.throws(sha.digest, | 295 Expect.throws(sha.digest, |
| 293 (e) => e is CryptoHashException); | 296 (e) => e is CryptoHashException); |
| 294 Expect.throws(() => sha.update([0]), | 297 Expect.throws(() => sha.update([0]), |
| 295 (e) => e is CryptoHashException); | 298 (e) => e is CryptoHashException); |
| 296 } | 299 } |
| 297 | 300 |
| 301 void testStandardVectors(inputs, mds) { |
| 302 for (var i = 0; i < inputs.length; i++) { |
| 303 var d = new SHA256().update(inputs[i]).digest(); |
| 304 Expect.equals(mds[i], digestToString(d), '$i'); |
| 305 } |
| 306 } |
| 307 |
| 298 void main() { | 308 void main() { |
| 299 test(); | 309 test(); |
| 300 testInvalidUse(); | 310 testInvalidUse(); |
| 311 testStandardVectors(sha256_long_inputs, sha256_long_mds); |
| 312 testStandardVectors(sha256_short_inputs, sha256_short_mds); |
| 301 } | 313 } |
| 302 | 314 |
| OLD | NEW |