OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:typed_data'; | 5 import 'dart:typed_data'; |
6 | 6 |
7 import 'package:typed_data/typed_data.dart'; | 7 import 'package:typed_data/typed_data.dart'; |
8 | 8 |
9 import 'digest.dart'; | 9 import 'digest.dart'; |
10 import 'utils.dart'; | 10 import 'utils.dart'; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 var lengthInBits = _lengthInBytes * bitsPerByte; | 121 var lengthInBits = _lengthInBytes * bitsPerByte; |
122 if (lengthInBits > maxUint64) { | 122 if (lengthInBits > maxUint64) { |
123 throw new UnsupportedError( | 123 throw new UnsupportedError( |
124 "Hashing is unsupported for messages with more than 2^64 bits."); | 124 "Hashing is unsupported for messages with more than 2^64 bits."); |
125 } | 125 } |
126 | 126 |
127 // Add the full length of the input data as a 64-bit value at the end of the | 127 // Add the full length of the input data as a 64-bit value at the end of the |
128 // hash. | 128 // hash. |
129 var offset = _pendingData.length; | 129 var offset = _pendingData.length; |
130 _pendingData.addAll(new Uint8List(8)); | 130 _pendingData.addAll(new Uint8List(8)); |
131 _pendingData.buffer.asByteData().setUint64(offset, lengthInBits, _endian); | 131 var byteData = _pendingData.buffer.asByteData(); |
132 | |
133 // We're essentially doing byteData.setUint64(offset, lengthInBits, _endian) | |
134 // here, but that method isn't supported on dart2js so we implement it | |
135 // manually instead. | |
136 var highBits = lengthInBits >> 32; | |
sra1
2016/03/23 22:15:50
This won't actually do what you want in dart2js.
d
nweiz
2016/03/23 22:21:26
Presumably in dart2js, lengthInBits can't be highe
| |
137 var lowBits = lengthInBits & mask32; | |
138 if (_endian == Endianness.BIG_ENDIAN) { | |
139 byteData.setUint32(offset, highBits, _endian); | |
140 byteData.setUint32(offset + bytesPerWord, lowBits, _endian); | |
141 } else { | |
142 byteData.setUint32(offset, lowBits, _endian); | |
143 byteData.setUint32(offset + bytesPerWord, highBits, _endian); | |
144 } | |
132 } | 145 } |
133 | 146 |
134 /// Rounds [val] up to the next multiple of [n], as long as [n] is a power of | 147 /// Rounds [val] up to the next multiple of [n], as long as [n] is a power of |
135 /// two. | 148 /// two. |
136 int _roundUp(int val, int n) => (val + n - 1) & -n; | 149 int _roundUp(int val, int n) => (val + n - 1) & -n; |
137 } | 150 } |
OLD | NEW |