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 // Library tag to allow the test to run on Dartium. | 5 // Library tag to allow the test to run on Dartium. |
6 library hmac_md5_test; | 6 library hmac_md5_test; |
7 | 7 |
8 import 'dart:crypto'; | 8 import 'dart:crypto'; |
9 | 9 |
10 // Data from http://tools.ietf.org/html/rfc2202. | 10 // Data from http://tools.ietf.org/html/rfc2202. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 const [0x56, 0x46, 0x1e, 0xf2, 0x34, 0x2e, 0xdc, 0x00, 0xf9, 0xba, | 92 const [0x56, 0x46, 0x1e, 0xf2, 0x34, 0x2e, 0xdc, 0x00, 0xf9, 0xba, |
93 0xb9, 0x95, 0x69, 0x0e, 0xfd, 0x4c], | 93 0xb9, 0x95, 0x69, 0x0e, 0xfd, 0x4c], |
94 const [0x6b, 0x1a, 0xb7, 0xfe, 0x4b, 0xd7, 0xbf, 0x8f, 0x0b, 0x62, | 94 const [0x6b, 0x1a, 0xb7, 0xfe, 0x4b, 0xd7, 0xbf, 0x8f, 0x0b, 0x62, |
95 0xe6, 0xce, 0x61, 0xb9, 0xd0, 0xcd], | 95 0xe6, 0xce, 0x61, 0xb9, 0xd0, 0xcd], |
96 const [0x6f, 0x63, 0x0f, 0xad, 0x67, 0xcd, 0xa0, 0xee, 0x1f, 0xb1, | 96 const [0x6f, 0x63, 0x0f, 0xad, 0x67, 0xcd, 0xa0, 0xee, 0x1f, 0xb1, |
97 0xf5, 0x62, 0xdb, 0x3a, 0xa5, 0x3e]]; | 97 0xf5, 0x62, 0xdb, 0x3a, 0xa5, 0x3e]]; |
98 | 98 |
99 void testStandardVectors(inputs, keys, string_macs, macs) { | 99 void testStandardVectors(inputs, keys, string_macs, macs) { |
100 for (var i = 0; i < inputs.length; i++) { | 100 for (var i = 0; i < inputs.length; i++) { |
101 var h = new HMAC(new MD5(), keys[i]); | 101 var h = new HMAC(new MD5(), keys[i]); |
102 var d = h.update(inputs[i]).digest(); | 102 h.add(inputs[i]); |
| 103 var d = h.close(); |
103 Expect.isTrue(CryptoUtils.bytesToHex(d).startsWith(string_macs[i]), '$i'); | 104 Expect.isTrue(CryptoUtils.bytesToHex(d).startsWith(string_macs[i]), '$i'); |
104 Expect.isTrue(h.verify(macs[i])); | 105 Expect.isTrue(h.verify(macs[i])); |
105 Expect.isFalse(h.verify(macs[(i+1)%macs.length])); | 106 Expect.isFalse(h.verify(macs[(i+1)%macs.length])); |
106 Expect.throws(() => h.verify([])); | 107 Expect.throws(() => h.verify([])); |
107 } | 108 } |
108 } | 109 } |
109 | 110 |
110 void main() { | 111 void main() { |
111 testStandardVectors(hmac_md5_inputs, hmac_md5_keys, | 112 testStandardVectors(hmac_md5_inputs, hmac_md5_keys, |
112 hmac_md5_string_macs, hmac_md5_macs); | 113 hmac_md5_string_macs, hmac_md5_macs); |
113 } | 114 } |
OLD | NEW |