Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1416)

Side by Side Diff: tests/lib/crypto/sha256_test.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/lib/crypto/sha1_test.dart ('k') | tests/lib/math/math2_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 tests. 5 // Library tag to allow Dartium to run the tests.
6 library sha256_test; 6 library sha256_test;
7 7
8 import 'dart:crypto'; 8 import 'dart:crypto';
9 9
10 part 'sha256_long_test_vectors.dart'; 10 part 'sha256_long_test_vectors.dart';
11 part 'sha256_short_test_vectors.dart'; 11 part 'sha256_short_test_vectors.dart';
12 12
13 List<int> createTestArr(int len) { 13 List<int> createTestArr(int len) {
14 var arr = new List<int>(len); 14 var arr = new List<int>.fixedLength(len);
15 for (var i = 0; i < len; i++) { 15 for (var i = 0; i < len; i++) {
16 arr[i] = i; 16 arr[i] = i;
17 } 17 }
18 return arr; 18 return arr;
19 } 19 }
20 20
21 void test() { 21 void test() {
22 final expected_values = const [ 22 final expected_values = const [
23 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 23 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
24 '6e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d', 24 '6e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d',
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 'c6fefe1bfbe6f5364bf0e40447ffca27fde55f1cd815e1fa3bafb46a41c91749', 271 'c6fefe1bfbe6f5364bf0e40447ffca27fde55f1cd815e1fa3bafb46a41c91749',
272 '552a69d052ae2980aa92ef44b4a8752fc585d70127d9df1ac53137e266786e4d', 272 '552a69d052ae2980aa92ef44b4a8752fc585d70127d9df1ac53137e266786e4d',
273 '369d7da16156c5e2c0d519cdbab3996a7249e20d3e48c36a3a873e987190bd89', 273 '369d7da16156c5e2c0d519cdbab3996a7249e20d3e48c36a3a873e987190bd89',
274 'ef67e0723230f6c535ff556e45ca2174e1e97deed306e9e87f1b65579076ec06', 274 'ef67e0723230f6c535ff556e45ca2174e1e97deed306e9e87f1b65579076ec06',
275 '2cb1e75cd7505a2783769276f30b122cb136fbbd03300510b71a7196ca670b37', 275 '2cb1e75cd7505a2783769276f30b122cb136fbbd03300510b71a7196ca670b37',
276 '1211b6885890be48f89934ec5246f1ce3cfff46c626cfcd686d5fdce9b1fb830', 276 '1211b6885890be48f89934ec5246f1ce3cfff46c626cfcd686d5fdce9b1fb830',
277 'd6a8bdb01e763fb64f3a02512e7be905679a5add6bb408f8750d679d17cad92f', 277 'd6a8bdb01e763fb64f3a02512e7be905679a5add6bb408f8750d679d17cad92f',
278 '3f8591112c6bbe5c963965954e293108b7208ed2af893e500d859368c654eabe' ]; 278 '3f8591112c6bbe5c963965954e293108b7208ed2af893e500d859368c654eabe' ];
279 279
280 for (var i = 0; i < expected_values.length; i++) { 280 for (var i = 0; i < expected_values.length; i++) {
281 var d = new SHA256().update(createTestArr(i)).digest(); 281 var hash = new SHA256();
282 hash.add(createTestArr(i));
283 var d = hash.close();
282 Expect.equals(expected_values[i], CryptoUtils.bytesToHex(d), '$i'); 284 Expect.equals(expected_values[i], CryptoUtils.bytesToHex(d), '$i');
283 } 285 }
284 } 286 }
285 287
286 void testInvalidUse() { 288 void testInvalidUse() {
287 var sha = new SHA256(); 289 var sha = new SHA256();
288 sha.digest(); 290 sha.close();
289 Expect.throws(() => sha.update([0]), (e) => e is HashException); 291 Expect.throws(() => sha.add([0]), (e) => e is HashException);
290 } 292 }
291 293
292 void testRepeatedDigest() { 294 void testRepeatedDigest() {
293 var sha = new SHA256(); 295 var sha = new SHA256();
294 var digest = sha.digest(); 296 var digest = sha.close();
295 Expect.listEquals(digest, sha.digest()); 297 Expect.listEquals(digest, sha.close());
296 } 298 }
297 299
298 void testStandardVectors(inputs, mds) { 300 void testStandardVectors(inputs, mds) {
299 for (var i = 0; i < inputs.length; i++) { 301 for (var i = 0; i < inputs.length; i++) {
300 var d = new SHA256().update(inputs[i]).digest(); 302 var hash = new SHA256();
303 hash.add(inputs[i]);
304 var d = hash.close();
301 Expect.equals(mds[i], CryptoUtils.bytesToHex(d), '$i'); 305 Expect.equals(mds[i], CryptoUtils.bytesToHex(d), '$i');
302 } 306 }
303 } 307 }
304 308
305 void main() { 309 void main() {
306 test(); 310 test();
307 testInvalidUse(); 311 testInvalidUse();
308 testRepeatedDigest(); 312 testRepeatedDigest();
309 testStandardVectors(sha256_long_inputs, sha256_long_mds); 313 testStandardVectors(sha256_long_inputs, sha256_long_mds);
310 testStandardVectors(sha256_short_inputs, sha256_short_mds); 314 testStandardVectors(sha256_short_inputs, sha256_short_mds);
311 } 315 }
312 316
OLDNEW
« no previous file with comments | « tests/lib/crypto/sha1_test.dart ('k') | tests/lib/math/math2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698