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

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

Issue 10332109: Make the crypto library an official dart:crypto library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix long line 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 | « lib/compiler/implementation/library_map.dart ('k') | runtime/bin/bin.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // TODO(ager, iposva): Get rid of this file when the VM snapshot
6 // generation can deal with normal library structure.
7
8 #library('crypto');
9
10 /**
11 * Interface for cryptographic hash functions.
12 *
13 * The [update] method is used to add data to the hash. The [digest] method
14 * is used to extract the message digest.
15 *
16 * Once the [digest] method has been called no more data can be added using the
17 * [update] method. If [update] is called after the first call to [digest] a
18 * HashException is thrown.
19 *
20 * If multiple instances of a given Hash is needed the [newInstance]
21 * method can provide a new instance.
22 */
23 interface Hash {
24 /**
25 * Add a list of bytes to the hash computation.
26 */
27 Hash update(List<int> data);
28
29 /**
30 * Finish the hash computation and extract the message digest as
31 * a list of bytes.
32 */
33 List<int> digest();
34
35 /**
36 * Returns a new instance of this hash function.
37 */
38 Hash newInstance();
39
40 /**
41 * Block size of the hash in bytes.
42 */
43 int get blockSize();
44 }
45
46 /**
47 * SHA1 hash function implementation.
48 */
49 interface SHA1 extends Hash default _SHA1 {
50 SHA1();
51 }
52
53 /**
54 * SHA256 hash function implementation.
55 */
56 interface SHA256 extends Hash default _SHA256 {
57 SHA256();
58 }
59
60 /**
61 * MD5 hash function implementation.
62 *
63 * WARNING: MD5 has known collisions and should only be used when
64 * required for backwards compatibility.
65 */
66 interface MD5 extends Hash default _MD5 {
67 MD5();
68 }
69
70 /**
71 * Hash-based Message Authentication Code support.
72 *
73 * The [update] method is used to add data to the message. The [digest] method
74 * is used to extract the message authentication code.
75 */
76 interface HMAC default _HMAC {
77 /**
78 * Create an [HMAC] object from a [Hash] and a key.
79 */
80 HMAC(Hash hash, List<int> key);
81
82 /**
83 * Add a list of bytes to the message.
84 */
85 HMAC update(List<int> data);
86
87 /**
88 * Perform the actual computation and extract the message digest
89 * as a list of bytes.
90 */
91 List<int> digest();
92 }
93
94 /**
95 * Utility methods for working with message digests.
96 */
97 class CryptoUtils {
98 /**
99 * Convert a list of bytes (for example a message digest) into a hex
100 * string.
101 */
102 static String bytesToHex(List<int> bytes) {
103 return _CryptoUtils.bytesToHex(bytes);
104 }
105 }
106
107 /**
108 * HashExceptions are thrown on invalid use of a Hash
109 * object.
110 */
111 class HashException {
112 HashException(String this.message);
113 toString() => "HashException: $message";
114 String message;
115 }
116
OLDNEW
« no previous file with comments | « lib/compiler/implementation/library_map.dart ('k') | runtime/bin/bin.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698