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 library crypto.hash_base; | 5 library crypto.hash_base; |
6 | 6 |
7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
8 | 8 |
9 import 'package:typed_data/typed_data.dart'; | 9 import 'package:typed_data/typed_data.dart'; |
10 | 10 |
11 import 'digest.dart'; | 11 import 'digest.dart'; |
12 import 'hash.dart'; | |
13 import 'utils.dart'; | 12 import 'utils.dart'; |
14 | 13 |
15 /// A base class for [Sink] implementations for hash algorithms. | 14 /// A base class for [Sink] implementations for hash algorithms. |
16 /// | 15 /// |
17 /// Subclasses should override [updateHash] and [digest]. | 16 /// Subclasses should override [updateHash] and [digest]. |
18 abstract class HashSink implements Sink<List<int>> { | 17 abstract class HashSink implements Sink<List<int>> { |
19 /// The inner sink that this should forward to. | 18 /// The inner sink that this should forward to. |
20 final Sink<Digest> _sink; | 19 final Sink<Digest> _sink; |
21 | 20 |
22 /// Whether the hash function operates on big-endian words. | 21 /// Whether the hash function operates on big-endian words. |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // hash. | 130 // hash. |
132 var offset = _pendingData.length; | 131 var offset = _pendingData.length; |
133 _pendingData.addAll(new Uint8List(8)); | 132 _pendingData.addAll(new Uint8List(8)); |
134 _pendingData.buffer.asByteData().setUint64(offset, lengthInBits, _endian); | 133 _pendingData.buffer.asByteData().setUint64(offset, lengthInBits, _endian); |
135 } | 134 } |
136 | 135 |
137 /// Rounds [val] up to the next multiple of [n], as long as [n] is a power of | 136 /// Rounds [val] up to the next multiple of [n], as long as [n] is a power of |
138 /// two. | 137 /// two. |
139 int _roundUp(int val, int n) => (val + n - 1) & -n; | 138 int _roundUp(int val, int n) => (val + n - 1) & -n; |
140 } | 139 } |
OLD | NEW |