OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 crypto.hash; | 5 library crypto.hash; |
6 | 6 |
7 /** | 7 /// An interface for cryptographic hash functions. |
8 * Interface for cryptographic hash functions. | 8 /// |
9 * | 9 /// The [add] method adds data to the hash. The [close] method extracts the |
10 * The [add] method is used to add data to the hash. The [close] method | 10 /// message digest. |
11 * is used to extract the message digest. | 11 /// |
12 * | 12 /// If multiple instances of a given Hash is needed, the [newInstance] method |
13 * Once the [close] method has been called no more data can be added using the | 13 /// can provide a new instance. |
14 * [add] method. If [add] is called after the first call to [close] a | |
15 * HashException is thrown. | |
16 * | |
17 * If multiple instances of a given Hash is needed the [newInstance] | |
18 * method can provide a new instance. | |
19 */ | |
20 // TODO(floitsch): make Hash implement Sink, EventSink or similar. | 14 // TODO(floitsch): make Hash implement Sink, EventSink or similar. |
21 abstract class Hash { | 15 abstract class Hash { |
22 /** | 16 /// Add a list of bytes to the hash computation. |
23 * Add a list of bytes to the hash computation. | 17 /// |
24 */ | 18 /// If [this] has already been closed, throws a [StateError]. |
25 void add(List<int> data); | 19 void add(List<int> data); |
26 | 20 |
27 /** | 21 /// Finish the hash computation and extract the message digest as a list of |
28 * Finish the hash computation and extract the message digest as | 22 /// bytes. |
29 * a list of bytes. | |
30 */ | |
31 List<int> close(); | 23 List<int> close(); |
32 | 24 |
33 /** | 25 /// Returns a new instance of this hash function. |
34 * Returns a new instance of this hash function. | |
35 */ | |
36 Hash newInstance(); | 26 Hash newInstance(); |
37 | 27 |
38 /** | 28 /// The internal block size of the hash in bytes. |
39 * Internal block size of the hash in bytes. | 29 /// |
40 * | 30 /// This is exposed for use by the [HMAC] class, which needs to know the block |
41 * This is exposed for use by the HMAC class which needs to know the | 31 /// size for the [Hash] it uses. |
42 * block size for the [Hash] it is using. | |
43 */ | |
44 int get blockSize; | 32 int get blockSize; |
45 } | 33 } |
OLD | NEW |