OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 #source("../../../../runtime/bin/sha1.dart"); | |
6 | |
7 void hexifyHash(List<int> data) { | |
8 Expect.equals(20, data.length); | |
9 StringBuffer sb = new StringBuffer(); | |
10 for (int i = 0; i < data.length; i++) { | |
11 String s = data[i].toRadixString(16); | |
12 if (s.length == 1) sb.add("0"); | |
13 sb.add(s); | |
14 } | |
15 return sb.toString().toLowerCase(); | |
16 } | |
17 | |
18 void main() { | |
19 String data; | |
20 | |
21 data = ""; | |
22 Expect.equals("da39a3ee5e6b4b0d3255bfef95601890afd80709", | |
23 hexifyHash(_Sha1._hash(data.charCodes()))); | |
24 | |
25 data = ""; | |
26 Expect.equals("db20d957030cd97e7b8ca33f43e065f65c736454", | |
27 hexifyHash(_Sha1._hash("Anders".charCodes()))); | |
28 | |
29 data = "Some random string"; | |
30 Expect.equals("f1660e7fa1265e89fd0c2f788c4f44ffaf9208b4", | |
31 hexifyHash(_Sha1._hash(data.charCodes()))); | |
32 | |
33 data = "The quick brown fox jumps over the lazy cog"; | |
34 Expect.equals("de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3", | |
35 hexifyHash(_Sha1._hash(data.charCodes()))); | |
36 | |
37 // Longest message which fits one chunk. | |
38 data = "The quick brown fox jumps over the lazy cog 12345678901"; | |
39 Expect.equals("ea413cd9eec1b65502bbf8c322cc026cf01cc994", | |
40 hexifyHash(_Sha1._hash(data.charCodes()))); | |
41 | |
42 // Shortest message which uses two chunks. | |
43 data = "The quick brown fox jumps over the lazy cog 123456789012"; | |
44 Expect.equals("3655a0787384d7d7236969da72e42d6dc32c8bb5", | |
45 hexifyHash(_Sha1._hash(data.charCodes()))); | |
46 | |
47 data = "The quick brown fox jumps over the lazy cog 1234567890123"; | |
48 Expect.equals("d8b6596a663569e47a5ae23cbc5acc241e0cae24", | |
49 hexifyHash(_Sha1._hash(data.charCodes()))); | |
50 | |
51 // From WebSocket standard. | |
52 data = "dGhlIHNhbXBsZSBub25jZQ==258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; | |
53 Expect.equals("b37a4f2cc0624f1690f64606cf385945b2bec4ea", | |
54 hexifyHash(_Sha1._hash(data.charCodes()))); | |
55 | |
56 data = "0123456789001234567890012345678900123456789001234567890" | |
57 "0123456789001234567890012345678900123456789001234567890"; | |
58 Expect.equals("534e82e5600593484251f42bd4855561a234a14b", | |
59 hexifyHash(_Sha1._hash(data.charCodes()))); | |
60 } | |
OLD | NEW |