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

Side by Side Diff: lib/crypto/crypto.dart

Issue 10170027: Implement HMAC support in lib/crypto. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update after test renaming. Added back lib testing in test.dart." Created 8 years, 7 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
« no previous file with comments | « no previous file | lib/crypto/hmac.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #library('crypto'); 5 #library('crypto');
6 6
7 #source('hmac.dart');
7 #source('sha_utils.dart'); 8 #source('sha_utils.dart');
8 #source('sha1.dart'); 9 #source('sha1.dart');
9 #source('sha256.dart'); 10 #source('sha256.dart');
10 11
11 /** 12 /**
12 * Interface for cryptographic hash functions. 13 * Interface for cryptographic hash functions.
13 * 14 *
14 * The [update] method is used to add data to the hash. The [digest] method 15 * The [update] method is used to add data to the hash. The [digest] method
15 * is used to extract the message digest. Once the [digest] method has been 16 * is used to extract the message digest.
16 * called the CryptoHash object is in an invalid state and should not be 17 *
17 * used again. If [digest] or [update] are called after the first call to 18 * Once the [digest] method has been called no more data can be added using the
18 * [digest] a CryptoHashException is thrown. 19 * [update] method. If [update] is called after the first call to [digest] a
20 * HashException is thrown.
21 *
22 * If multiple instances of a given Hash is needed the [newInstance]
23 * method can provide a new instance.
19 */ 24 */
20 interface CryptoHash { 25 interface Hash {
21 /** 26 /**
22 * Add a list of bytes to the hash computation. 27 * Add a list of bytes to the hash computation.
23 */ 28 */
24 CryptoHash update(List<int> data); 29 Hash update(List<int> data);
25 30
26 /** 31 /**
27 * Finish the hash computation and extract the message digest as 32 * Finish the hash computation and extract the message digest as
28 * a list of bytes. 33 * a list of bytes.
29 */ 34 */
30 List<int> digest(); 35 List<int> digest();
36
37 /**
38 * Returns a new instance of this hash function.
39 */
40 Hash newInstance();
41
42 /**
43 * Block size of the hash in bytes.
44 */
45 int get blockSize();
31 } 46 }
32 47
33 /** 48 /**
34 * SHA1 hash function implementation. 49 * SHA1 hash function implementation.
35 */ 50 */
36 interface SHA1 extends CryptoHash default _SHA1 { 51 interface SHA1 extends Hash default _SHA1 {
37 SHA1(); 52 SHA1();
38 } 53 }
39 54
40 /** 55 /**
41 * SHA256 hash function implementation. 56 * SHA256 hash function implementation.
42 */ 57 */
43 interface SHA256 extends CryptoHash default _SHA256 { 58 interface SHA256 extends Hash default _SHA256 {
44 SHA256(); 59 SHA256();
45 } 60 }
46 61
47 62
48 /** 63 /**
49 * CryptoHashExceptions are thrown on invalid use of a CryptoHash 64 * Hash-based Message Authentication Code support.
65 *
66 * The [update] method is used to add data to the message. The [digest] method
67 * is used to extract the message authentication code.
68 */
69 interface HMAC default _HMAC {
70 /**
71 * Create an [HMAC] object from a [Hash] and a key.
72 */
73 HMAC(Hash hash, List<int> key);
74
75 /**
76 * Add a list of bytes to the message.
77 */
78 HMAC update(List<int> data);
79
80 /**
81 * Perform the actual computation and extract the message digest
82 * as a list of bytes.
83 */
84 List<int> digest();
85 }
86
87
88 /**
89 * HashExceptions are thrown on invalid use of a Hash
50 * object. 90 * object.
51 */ 91 */
52 class CryptoHashException { 92 class HashException {
53 CryptoHashException(String this.message); 93 HashException(String this.message);
54 toString() => "CryptoHashException: $message"; 94 toString() => "HashException: $message";
55 String message; 95 String message;
56 } 96 }
57 97
OLDNEW
« no previous file with comments | « no previous file | lib/crypto/hmac.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698