Skip to content

Commit

Permalink
vendor Object.hashAll
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto committed Aug 26, 2022
1 parent a9a9361 commit 163ddcf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dart/lib/src/cryptography/digest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import 'dart:typed_data';
import '../utils/hash_code.dart';

/// A message digest as computed by a `Hash` or `HMAC` function.
class Digest {
Expand Down Expand Up @@ -34,7 +35,7 @@ class Digest {
}

@override
int get hashCode => Object.hashAll(bytes);
int get hashCode => hashAll(bytes);

/// The message digest as a string of hexadecimal digits.
@override
Expand Down
10 changes: 9 additions & 1 deletion dart/lib/src/utils/hash_code.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Borrowed from https://api.dart.dev/stable/2.17.6/dart-core/Object/hash.html
// Since Object.hash(a, b) is only available from Dart 2.14
// Since Object.hash(a, b) and Object.hashAll are only available from Dart 2.14

// A per-isolate seed for hash code computations.
final int _hashSeed = identityHashCode(Object);
Expand All @@ -22,3 +22,11 @@ int _finish(int hash) {
hash = hash ^ (hash >> 11);
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
}

int hashAll(Iterable<Object?> objects) {
int hash = _hashSeed;
for (var object in objects) {
hash = _combine(hash, object.hashCode);
}
return _finish(hash);
}

0 comments on commit 163ddcf

Please sign in to comment.