File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ export 'src/base64.dart';
8
8
export 'src/base64/decoder.dart' ;
9
9
export 'src/base64/encoder.dart' ;
10
10
export 'src/crypto_utils.dart' ;
11
+ export 'src/digest.dart' ;
11
12
export 'src/hash.dart' ;
12
13
export 'src/hmac.dart' ;
13
14
export 'src/md5.dart' ;
Original file line number Diff line number Diff line change
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
3
+ // BSD-style license that can be found in the LICENSE file.
4
+
5
+ library crypto.digest;
6
+
7
+ import 'dart:typed_data' ;
8
+
9
+ import 'crypto_utils.dart' ;
10
+
11
+ /// A message digest as computed by a [Hash] or [HMAC] function.
12
+ class Digest {
13
+ /// The message digest as an array of bytes.
14
+ final List <int > bytes;
15
+
16
+ Digest (List <int > bytes)
17
+ : bytes = new Uint8List .fromList (bytes);
18
+
19
+ /// Returns whether this is equal to another digest.
20
+ ///
21
+ /// This should be used instead of manual comparisons to avoid leaking
22
+ /// information via timing.
23
+ bool operator == (Object other) {
24
+ if (other is ! Digest ) return false ;
25
+ if (other.bytes.length != bytes.length) return false ;
26
+
27
+ var result = 0 ;
28
+ for (var i = 0 ; i < bytes.length; i++ ) {
29
+ result | = bytes[i] ^ other.bytes[i];
30
+ }
31
+ return result == 0 ;
32
+ }
33
+
34
+ /// The message digest as a string of hexadecimal digits.
35
+ String toString () => CryptoUtils .bytesToHex (bytes);
36
+ }
You can’t perform that action at this time.
0 commit comments