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

Unified Diff: lib/src/sha256.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/sha1.dart ('k') | test/sha1_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/sha256.dart
diff --git a/lib/src/sha256.dart b/lib/src/sha256.dart
index ca2f3379a241a25af8c6989ca3f2cc31c8a04dce..09c3c69a86413c83d2a6e48645fef2cd578ab3d5 100644
--- a/lib/src/sha256.dart
+++ b/lib/src/sha256.dart
@@ -4,19 +4,37 @@
library crypto.sha256;
+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 [SHA256].
+///
+/// This instance provides convenient access to the [SHA256][rfc] hash function.
+///
+/// [rfc]: http://tools.ietf.org/html/rfc6234
+final sha256 = new SHA256();
+
/// An implementation of the [SHA-256][rfc] hash function.
///
/// [rfc]: http://tools.ietf.org/html/rfc6234
-abstract class SHA256 implements Hash {
- factory SHA256() = _SHA256;
+///
+/// Note that it's almost always easier to use [sha256] rather than creating a
+/// new instance.
+class SHA256 extends Hash {
+ final int blockSize = 16 * bytesPerWord;
+
+ @Deprecated("Use the sha256 field instead.")
+ SHA256();
- SHA256 newInstance();
+ SHA256 newInstance() => new SHA256();
+
+ ByteConversionSink startChunkedConversion(Sink<Digest> sink) =>
+ new ByteConversionSink.from(new _SHA256Sink(sink));
}
/// Data from a non-linear function that functions as reproducible noise.
@@ -38,7 +56,7 @@ const List<int> _noise = const [
///
/// This is separate so that it can extend [HashBase] without leaking additional
/// public memebers.
-class _SHA256 extends HashBase implements SHA256 {
+class _SHA256Sink extends HashSink {
final digest = new Uint32List(8);
/// The sixteen words from the original chunk, extended to 64 words.
@@ -47,9 +65,9 @@ class _SHA256 extends HashBase implements SHA256 {
/// used across invocations of [updateHash].
final Uint32List _extended;
- _SHA256()
+ _SHA256Sink(Sink<Digest> sink)
: _extended = new Uint32List(64),
- super(16) {
+ super(sink, 16) {
// Initial value of the hash parts. First 32 bits of the fractional parts
// of the square roots of the first 8 prime numbers.
digest[0] = 0x6a09e667;
@@ -62,8 +80,6 @@ class _SHA256 extends HashBase implements SHA256 {
digest[7] = 0x5be0cd19;
}
- SHA256 newInstance() => new _SHA256();
-
// The following helper functions are taken directly from
// http://tools.ietf.org/html/rfc6234.
« no previous file with comments | « lib/src/sha1.dart ('k') | test/sha1_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698