| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 } | 63 } |
| 64 | 64 |
| 65 void close() { | 65 void close() { |
| 66 if (_isClosed) return; | 66 if (_isClosed) return; |
| 67 _isClosed = true; | 67 _isClosed = true; |
| 68 | 68 |
| 69 _finalizeData(); | 69 _finalizeData(); |
| 70 _iterate(); | 70 _iterate(); |
| 71 assert(_pendingData.isEmpty); | 71 assert(_pendingData.isEmpty); |
| 72 _sink.add(new Digest(_byteDigest())); | 72 _sink.add(new Digest(_byteDigest())); |
| 73 _sink.close(); |
| 73 } | 74 } |
| 74 | 75 |
| 75 Uint8List _byteDigest() { | 76 Uint8List _byteDigest() { |
| 76 if (_endian == Endianness.HOST_ENDIAN) return digest.buffer.asUint8List(); | 77 if (_endian == Endianness.HOST_ENDIAN) return digest.buffer.asUint8List(); |
| 77 | 78 |
| 78 var byteDigest = new Uint8List(digest.lengthInBytes); | 79 var byteDigest = new Uint8List(digest.lengthInBytes); |
| 79 var byteData = byteDigest.buffer.asByteData(); | 80 var byteData = byteDigest.buffer.asByteData(); |
| 80 for (var i = 0; i < digest.length; i++) { | 81 for (var i = 0; i < digest.length; i++) { |
| 81 byteData.setUint32(i * bytesPerWord, digest[i]); | 82 byteData.setUint32(i * bytesPerWord, digest[i]); |
| 82 } | 83 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } else { | 142 } else { |
| 142 byteData.setUint32(offset, lowBits, _endian); | 143 byteData.setUint32(offset, lowBits, _endian); |
| 143 byteData.setUint32(offset + bytesPerWord, highBits, _endian); | 144 byteData.setUint32(offset + bytesPerWord, highBits, _endian); |
| 144 } | 145 } |
| 145 } | 146 } |
| 146 | 147 |
| 147 /// Rounds [val] up to the next multiple of [n], as long as [n] is a power of | 148 /// Rounds [val] up to the next multiple of [n], as long as [n] is a power of |
| 148 /// two. | 149 /// two. |
| 149 int _roundUp(int val, int n) => (val + n - 1) & -n; | 150 int _roundUp(int val, int n) => (val + n - 1) & -n; |
| 150 } | 151 } |
| OLD | NEW |