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

Side by Side Diff: tests/lib/src/crypto/sha1Test.dart

Issue 10134055: Add common interface for cryptographic hash functions to lib/crypto.dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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
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 // 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 List<int> createTestArr(int len) { 8 List<int> createTestArr(int len) {
9 var arr = new List<int>(len); 9 var arr = new List<int>(len);
10 for (var i = 0; i < len; i++) { 10 for (var i = 0; i < len; i++) {
11 arr[i] = i; 11 arr[i] = i;
12 } 12 }
13 return arr; 13 return arr;
14 } 14 }
15 15
16 String digestToString(List<int> digest) { 16 String digestToString(List<int> digest) {
17 var buf = new StringBuffer(); 17 var buf = new StringBuffer();
18 for (var part in digest) { 18 for (var part in digest) {
19 buf.add("${(part < 16) ? "0" : ""}${part.toRadixString(16).toLowerCase()}"); 19 buf.add("${(part < 16) ? "0" : ""}${part.toRadixString(16).toLowerCase()}");
20 } 20 }
21 return buf.toString(); 21 return buf.toString();
22 } 22 }
23 23
24 void testStatic() { 24 void testStatic() {
25 final expected_values = const [ 25 final expected_values = const [
Ben Laurie (Google) 2012/04/25 13:17:13 Where did these values come from? What about stand
Mads Ager (google) 2012/04/25 13:39:34 These values came from another library. Adding sta
Ivan Posva 2012/04/25 13:44:22 These values were generated using a different SHA-
26 "da39a3ee5e6b4b0d3255bfef95601890afd80709", 26 "da39a3ee5e6b4b0d3255bfef95601890afd80709",
27 "5ba93c9db0cff93f52b521d7420e43f6eda2784f", 27 "5ba93c9db0cff93f52b521d7420e43f6eda2784f",
28 "3f29546453678b855931c174a97d6c0894b8f546", 28 "3f29546453678b855931c174a97d6c0894b8f546",
29 "0c7a623fd2bbc05b06423be359e4021d36e721ad", 29 "0c7a623fd2bbc05b06423be359e4021d36e721ad",
30 "a02a05b025b928c039cf1ae7e8ee04e7c190c0db", 30 "a02a05b025b928c039cf1ae7e8ee04e7c190c0db",
31 "1cf251472d59f8fadeb3ab258e90999d8491be19", 31 "1cf251472d59f8fadeb3ab258e90999d8491be19",
32 "868460d98d09d8bbb93d7b6cdd15cc7fbec676b9", 32 "868460d98d09d8bbb93d7b6cdd15cc7fbec676b9",
33 "6dc86f11b8cdbe879bf8ba3832499c2f93c729ba", 33 "6dc86f11b8cdbe879bf8ba3832499c2f93c729ba",
34 "67423ebfa8454f19ac6f4686d6c0dc731a3ddd6b", 34 "67423ebfa8454f19ac6f4686d6c0dc731a3ddd6b",
35 "63bf60c7105a07a2b125bbf89e61abdabc6978c2", 35 "63bf60c7105a07a2b125bbf89e61abdabc6978c2",
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 "6ae457f71b1cd60b1810fd4379c90bb38154568f", 531 "6ae457f71b1cd60b1810fd4379c90bb38154568f",
532 "063623280f208df296895ccd867dab8a73cf174d", 532 "063623280f208df296895ccd867dab8a73cf174d",
533 "7a8b8c9aa0591603cf08e94ec2ae6a6350cbb8a2", 533 "7a8b8c9aa0591603cf08e94ec2ae6a6350cbb8a2",
534 "20c4232d3066c41e211eefe2834db78a8c083ea4", 534 "20c4232d3066c41e211eefe2834db78a8c083ea4",
535 "82fdf2cccc77ab556aa35557d0923b162d1b98cf", 535 "82fdf2cccc77ab556aa35557d0923b162d1b98cf",
536 "3dce8306f3c1810d5d81ed5ebb0ccea947277a61", 536 "3dce8306f3c1810d5d81ed5ebb0ccea947277a61",
537 "11bca5b61fc1f6d59078ec5354bc6d9adecc0c5d", 537 "11bca5b61fc1f6d59078ec5354bc6d9adecc0c5d",
538 ]; 538 ];
539 for (var i = 0; i < expected_values.length; i++) { 539 for (var i = 0; i < expected_values.length; i++) {
540 Expect.equals(expected_values[i], 540 Expect.equals(expected_values[i],
541 digestToString(SHA1.digest(createTestArr(i)))); 541 digestToString(new SHA1().update(createTestArr(i)).digest()));
542 } 542 }
543 } 543 }
544 544
545 void main() { 545 void main() {
546 testStatic(); 546 testStatic();
547 } 547 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698