OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart.crypto; | 5 part of dart.crypto; |
6 | 6 |
7 /** | 7 /** |
8 * Interface for cryptographic hash functions. | 8 * Interface for cryptographic hash functions. |
9 * | 9 * |
10 * The [add] method is used to add data to the hash. The [close] method | 10 * The [add] method is used to add data to the hash. The [close] method |
11 * is used to extract the message digest. | 11 * is used to extract the message digest. |
12 * | 12 * |
13 * Once the [close] method has been called no more data can be added using the | 13 * Once the [close] method has been called no more data can be added using the |
14 * [add] method. If [add] is called after the first call to [close] a | 14 * [add] method. If [add] is called after the first call to [close] a |
15 * HashException is thrown. | 15 * HashException is thrown. |
16 * | 16 * |
17 * If multiple instances of a given Hash is needed the [newInstance] | 17 * If multiple instances of a given Hash is needed the [newInstance] |
18 * method can provide a new instance. | 18 * method can provide a new instance. |
19 */ | 19 */ |
20 // TODO(floitsch): make Hash implement Sink, StreamSink or similar. | 20 // TODO(floitsch): make Hash implement Sink, EventSink or similar. |
21 abstract class Hash { | 21 abstract class Hash { |
22 /** | 22 /** |
23 * Add a list of bytes to the hash computation. | 23 * Add a list of bytes to the hash computation. |
24 */ | 24 */ |
25 add(List<int> data); | 25 add(List<int> data); |
26 | 26 |
27 /** | 27 /** |
28 * Finish the hash computation and extract the message digest as | 28 * Finish the hash computation and extract the message digest as |
29 * a list of bytes. | 29 * a list of bytes. |
30 */ | 30 */ |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 abstract class MD5 implements Hash { | 67 abstract class MD5 implements Hash { |
68 factory MD5() => new _MD5(); | 68 factory MD5() => new _MD5(); |
69 } | 69 } |
70 | 70 |
71 /** | 71 /** |
72 * Hash-based Message Authentication Code support. | 72 * Hash-based Message Authentication Code support. |
73 * | 73 * |
74 * The [add] method is used to add data to the message. The [digest] and | 74 * The [add] method is used to add data to the message. The [digest] and |
75 * [close] methods are used to extract the message authentication code. | 75 * [close] methods are used to extract the message authentication code. |
76 */ | 76 */ |
77 // TODO(floitsch): make Hash implement Sink, StreamSink or similar. | 77 // TODO(floitsch): make Hash implement Sink, EventSink or similar. |
78 abstract class HMAC { | 78 abstract class HMAC { |
79 /** | 79 /** |
80 * Create an [HMAC] object from a [Hash] and a key. | 80 * Create an [HMAC] object from a [Hash] and a key. |
81 */ | 81 */ |
82 factory HMAC(Hash hash, List<int> key) => new _HMAC(hash, key); | 82 factory HMAC(Hash hash, List<int> key) => new _HMAC(hash, key); |
83 | 83 |
84 /** | 84 /** |
85 * Add a list of bytes to the message. | 85 * Add a list of bytes to the message. |
86 */ | 86 */ |
87 add(List<int> data); | 87 add(List<int> data); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 /** | 135 /** |
136 * HashExceptions are thrown on invalid use of a Hash | 136 * HashExceptions are thrown on invalid use of a Hash |
137 * object. | 137 * object. |
138 */ | 138 */ |
139 class HashException { | 139 class HashException { |
140 HashException(String this.message); | 140 HashException(String this.message); |
141 toString() => "HashException: $message"; | 141 toString() => "HashException: $message"; |
142 String message; | 142 String message; |
143 } | 143 } |
144 | 144 |
OLD | NEW |