Prepare dart/crypto library for limiting integers to 64 bits in Dart (#37)
* Prepare dart/crypto library for limiting integers to 64 bits in Dart
* Changed version to 2.0.2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 36c080a..1417775 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 2.0.2
+
+* Prepare `HashSink` implementation for limiting integers to 64 bits in Dart
+ language.
+
## 2.0.1
* Support `convert` 2.0.0.
diff --git a/lib/src/hash_sink.dart b/lib/src/hash_sink.dart
index 9d70746..369d3e3 100644
--- a/lib/src/hash_sink.dart
+++ b/lib/src/hash_sink.dart
@@ -25,6 +25,10 @@
/// used across invocations of [_iterate].
final Uint32List _currentChunk;
+ /// Messages with more than 2^64-1 bits are not supported.
+ /// So the maximum length in bytes is (2^64-1)/8.
+ static const _maxMessageLengthInBytes = 0x1fffffffffffffff;
+
/// The length of the input data so far, in bytes.
int _lengthInBytes = 0;
@@ -121,12 +125,13 @@
_pendingData.add(0);
}
- var lengthInBits = _lengthInBytes * bitsPerByte;
- if (lengthInBits > maxUint64) {
+ if (_lengthInBytes > _maxMessageLengthInBytes) {
throw new UnsupportedError(
"Hashing is unsupported for messages with more than 2^64 bits.");
}
+ var lengthInBits = _lengthInBytes * bitsPerByte;
+
// Add the full length of the input data as a 64-bit value at the end of the
// hash.
var offset = _pendingData.length;
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index ec72878..9ac8efc 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -5,9 +5,6 @@
/// A bitmask that limits an integer to 32 bits.
const mask32 = 0xFFFFFFFF;
-/// The highest value representable by a 64-bit unsigned integer.
-const maxUint64 = 0xFFFFFFFFFFFFFFFF;
-
/// The number of bits in a byte.
const bitsPerByte = 8;
diff --git a/pubspec.yaml b/pubspec.yaml
index 5a5193f..81ea3c6 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: crypto
-version: 2.0.2-dev
+version: 2.0.2
author: Dart Team <misc@dartlang.org>
description: Library of cryptographic functions.
homepage: https://www.github.com/dart-lang/crypto