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

Unified Diff: lib/src/md5.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/hmac.dart ('k') | lib/src/sha1.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/md5.dart
diff --git a/lib/src/md5.dart b/lib/src/md5.dart
index 3cae7fcaeeb0dbb9d99063a077f5cc59185a28a4..1964bc20ad8f50ea1389ca704ddb995f2a5d0d33 100644
--- a/lib/src/md5.dart
+++ b/lib/src/md5.dart
@@ -4,22 +4,43 @@
library crypto.md5;
+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 [MD5].
+///
+/// This instance provides convenient access to the [MD5][rfc] hash function.
+///
+/// [rfc]: https://tools.ietf.org/html/rfc1321
+///
+/// **Warning**: MD5 has known collisions and should only be used when required
+/// for backwards compatibility.
+final md5 = new MD5._();
+
/// An implementation of the [MD5][rfc] hash function.
///
/// [rfc]: https://tools.ietf.org/html/rfc1321
///
/// **Warning**: MD5 has known collisions and should only be used when required
/// for backwards compatibility.
-abstract class MD5 implements Hash {
- factory MD5() = _MD5;
+///
+/// Note that it's almost always easier to use [md5] rather than creating a new
+/// instance.
+class MD5 extends Hash {
+ final int blockSize = 16 * bytesPerWord;
+
+ @Deprecated("Use the md5 field instead.")
+ MD5();
- MD5 newInstance();
+ MD5 newInstance() => new MD5._();
+
+ ByteConversionSink startChunkedConversion(Sink<Digest> sink) =>
+ new ByteConversionSink.from(new _MD5Sink(sink));
}
/// Data from a non-linear mathematical function that functions as
@@ -50,18 +71,17 @@ const _shiftAmounts = const [
///
/// This is separate so that it can extend [HashBase] without leaking additional
/// public memebers.
-class _MD5 extends HashBase implements MD5 {
+class _MD5Sink extends HashSink {
final digest = new Uint32List(4);
- _MD5() : super(16, endian: Endianness.LITTLE_ENDIAN) {
+ _MD5Sink(Sink<Digest> sink)
+ : super(sink, 16, endian: Endianness.LITTLE_ENDIAN) {
digest[0] = 0x67452301;
digest[1] = 0xefcdab89;
digest[2] = 0x98badcfe;
digest[3] = 0x10325476;
}
- MD5 newInstance() => new _MD5();
-
void updateHash(Uint32List chunk) {
assert(chunk.length == 16);
« no previous file with comments | « lib/src/hmac.dart ('k') | lib/src/sha1.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698