Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Unified Diff: lib/src/hash_sink.dart

Issue 1355223002: Change Hash subclasses to be Converters. (Closed) Base URL: git@github.com:dart-lang/crypto.git@master
Patch Set: Code review changes Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/hash_base.dart ('k') | lib/src/hmac.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/hash_sink.dart
diff --git a/lib/src/hash_base.dart b/lib/src/hash_sink.dart
similarity index 91%
rename from lib/src/hash_base.dart
rename to lib/src/hash_sink.dart
index 8cd2ad5e502155288488f58164d6c1d8412715b5..c5986e528b86db170af53c33593cc5eb0dc213ab 100644
--- a/lib/src/hash_base.dart
+++ b/lib/src/hash_sink.dart
@@ -8,13 +8,17 @@ import 'dart:typed_data';
import 'package:typed_data/typed_data.dart';
+import 'digest.dart';
import 'hash.dart';
import 'utils.dart';
-/// A base class for [Hash] implementations.
+/// A base class for [Sink] implementations for hash algorithms.
///
/// Subclasses should override [updateHash] and [digest].
-abstract class HashBase implements Hash {
+abstract class HashSink implements Sink<List<int>> {
+ /// The inner sink that this should forward to.
+ final Sink<Digest> _sink;
+
/// Whether the hash function operates on big-endian words.
final Endianness _endian;
@@ -38,13 +42,12 @@ abstract class HashBase implements Hash {
/// This should be updated each time [updateHash] is called.
Uint32List get digest;
- int get blockSize => _currentChunk.lengthInBytes;
-
/// Creates a new hash.
///
/// [chunkSizeInWords] represents the size of the input chunks processed by
/// the algorithm, in terms of 32-bit words.
- HashBase(int chunkSizeInWords, {Endianness endian: Endianness.BIG_ENDIAN})
+ HashSink(this._sink, int chunkSizeInWords,
+ {Endianness endian: Endianness.BIG_ENDIAN})
: _endian = endian,
_currentChunk = new Uint32List(chunkSizeInWords);
@@ -62,14 +65,14 @@ abstract class HashBase implements Hash {
_iterate();
}
- List<int> close() {
- if (_isClosed) return _byteDigest();
+ void close() {
+ if (_isClosed) return;
_isClosed = true;
_finalizeData();
_iterate();
assert(_pendingData.isEmpty);
- return _byteDigest();
+ _sink.add(new Digest(_byteDigest()));
}
Uint8List _byteDigest() {
« no previous file with comments | « lib/src/hash_base.dart ('k') | lib/src/hmac.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698