Chromium Code Reviews| Index: lib/src/utils.dart |
| diff --git a/lib/src/utils.dart b/lib/src/utils.dart |
| index 569a04f626a2877addfc31c05d873d795deccbd9..9683223b008a9b452c16aea02bee5a6b2b4ef478 100644 |
| --- a/lib/src/utils.dart |
| +++ b/lib/src/utils.dart |
| @@ -8,7 +8,8 @@ import "dart:convert"; |
| import 'dart:io'; |
| import 'dart:math' as math; |
| -import "package:crypto/crypto.dart"; |
| +import "package:convert/convert.dart"; |
| +import "package:crypto/crypto.dart" as crypto; |
|
nweiz
2016/04/21 19:04:38
crypto is not intended to be imported with a prefi
Bob Nystrom
2016/04/21 20:23:20
Pub defines a sha1() function so I needed to disam
|
| import 'package:path/path.dart' as path; |
| import "package:stack_trace/stack_trace.dart"; |
| @@ -486,10 +487,33 @@ bool endsWithPattern(String str, Pattern matcher) { |
| } |
| /// Returns the hex-encoded sha1 hash of [source]. |
| -String sha1(String source) { |
| - var sha = new SHA1(); |
| - sha.add(source.codeUnits); |
| - return CryptoUtils.bytesToHex(sha.close()); |
| +String sha1(String source) => |
| + hex.encode(crypto.sha1.convert(source.codeUnits).bytes); |
|
nweiz
2016/04/21 19:04:38
crypto.sha1.convert(UTF8.encode(source)).toString(
Bob Nystrom
2016/04/21 20:23:20
TIL. Done. I'll send out a code review.
|
| + |
| +/// Returns the base64-encoded sha1 hash of [stream]. |
|
nweiz
2016/04/21 19:04:38
Why is this base64-encoded rather than hex-encoded
Bob Nystrom
2016/04/21 20:23:20
It's annoying that this is different from the prev
|
| +Future<String> sha1Stream(Stream<List<int>> stream) async { |
| + crypto.Digest digest; |
| + |
| + var digestSink = new ChunkedConversionSink<crypto.Digest>.withCallback( |
| + (digests) { |
| + digest = digests.single; |
| + }); |
| + |
| + var byteSink = crypto.sha1.startChunkedConversion(digestSink); |
| + |
| + await stream.forEach((chunk) { |
| + byteSink.add(chunk); |
| + }); |
| + |
| + byteSink.close(); |
| + |
| + // TODO(rnystrom): this call to `close` should not be needed. Remove when |
| + // https://github.com/dart-lang/crypto/issues/33 |
| + // is fixed. |
| + // Does not cause any problems in the mean time. |
| + digestSink.close(); |
| + |
| + return BASE64.encode(digest.bytes); |
| } |
| /// Configures [future] so that its result (success or exception) is passed on |