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

Unified Diff: lib/src/sha1.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/md5.dart ('k') | lib/src/sha256.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/sha1.dart
diff --git a/lib/src/sha1.dart b/lib/src/sha1.dart
index 098b0a841725ebf53411a2117ae247eaaba101d5..300147f7abc82c37aa433064a89407c0fac74c73 100644
--- a/lib/src/sha1.dart
+++ b/lib/src/sha1.dart
@@ -4,26 +4,44 @@
library crypto.sha1;
+import 'dart:convert';
import 'dart:typed_data';
+import 'digest.dart';
import 'hash.dart';
-import 'hash_base.dart';
+import 'hash_sink.dart';
import 'utils.dart';
+/// An instance of [SHA1].
+///
+/// This instance provides convenient access to the [SHA1][rfc] hash function.
+///
+/// [rfc]: http://tools.ietf.org/html/rfc3174
+final sha1 = new SHA1();
+
/// An implementation of the [SHA-1][rfc] hash function.
///
/// [rfc]: http://tools.ietf.org/html/rfc3174
-abstract class SHA1 implements Hash {
- factory SHA1() = _SHA1;
+///
+/// Note that it's almost always easier to use [sha1] rather than creating a new
+/// instance.
+class SHA1 extends Hash {
+ final int blockSize = 16 * bytesPerWord;
+
+ @Deprecated("Use the sha1 field instead.")
+ SHA1();
- SHA1 newInstance();
+ SHA1 newInstance() => new SHA1();
+
+ ByteConversionSink startChunkedConversion(Sink<Digest> sink) =>
+ new ByteConversionSink.from(new _SHA1Sink(sink));
}
/// The concrete implementation of [SHA1].
///
/// This is separate so that it can extend [HashBase] without leaking additional
/// public memebers.
-class _SHA1 extends HashBase implements SHA1 {
+class _SHA1Sink extends HashSink {
final digest = new Uint32List(5);
/// The sixteen words from the original chunk, extended to 80 words.
@@ -32,9 +50,9 @@ class _SHA1 extends HashBase implements SHA1 {
/// used across invocations of [updateHash].
final Uint32List _extended;
- _SHA1()
+ _SHA1Sink(Sink<Digest> sink)
: _extended = new Uint32List(80),
- super(16) {
+ super(sink, 16) {
digest[0] = 0x67452301;
digest[1] = 0xEFCDAB89;
digest[2] = 0x98BADCFE;
@@ -42,8 +60,6 @@ class _SHA1 extends HashBase implements SHA1 {
digest[4] = 0xC3D2E1F0;
}
- SHA1 newInstance() => new _SHA1();
-
void updateHash(Uint32List chunk) {
assert(chunk.length == 16);
« no previous file with comments | « lib/src/md5.dart ('k') | lib/src/sha256.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698