Skip to content

Commit

Permalink
Avoid calling ByteData.setUint64.
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Mar 23, 2016
1 parent 72c7471 commit 8882b9d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.2+1

* Avoid core library methods that don't work on dart2js.

## 0.9.2

* `Hash`, `MD5`, `SHA1`, and `SHA256` now implement `Converter`. They convert
Expand Down
15 changes: 14 additions & 1 deletion lib/src/hash_sink.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,20 @@ abstract class HashSink implements Sink<List<int>> {
// hash.
var offset = _pendingData.length;
_pendingData.addAll(new Uint8List(8));
_pendingData.buffer.asByteData().setUint64(offset, lengthInBits, _endian);
var byteData = _pendingData.buffer.asByteData();

// We're essentially doing byteData.setUint64(offset, lengthInBits, _endian)
// here, but that method isn't supported on dart2js so we implement it
// manually instead.
var highBits = lengthInBits >> 32;
var lowBits = lengthInBits & mask32;
if (_endian == Endianness.BIG_ENDIAN) {
byteData.setUint32(offset, highBits, _endian);
byteData.setUint32(offset + bytesPerWord, lowBits, _endian);
} else {
byteData.setUint32(offset, lowBits, _endian);
byteData.setUint32(offset + bytesPerWord, highBits, _endian);
}
}

/// Rounds [val] up to the next multiple of [n], as long as [n] is a power of
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: crypto
version: 0.9.2
version: 0.9.2+1
author: Dart Team <[email protected]>
description: Library of cryptographic functions.
homepage: https://www.github.com/dart-lang/crypto
Expand Down
3 changes: 0 additions & 3 deletions test/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:math' as math;
import 'dart:io';

import 'package:crypto/crypto.dart';
import 'package:test/test.dart';

Expand Down

0 comments on commit 8882b9d

Please sign in to comment.