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

Unified Diff: pkg/compiler/lib/src/hash/sha1.dart

Issue 830703004: Emit to StreamCodeOutput instead of CodeBuffer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments Created 5 years, 11 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 | « pkg/compiler/lib/src/deferred_load.dart ('k') | pkg/compiler/lib/src/io/code_output.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/hash/sha1.dart
diff --git a/pkg/compiler/lib/src/hash/sha1.dart b/pkg/compiler/lib/src/hash/sha1.dart
index 949621d0c64bed7f381f466f84485faee28380bb..60716a48b8c69e645785a36e590dcb5005e0043e 100644
--- a/pkg/compiler/lib/src/hash/sha1.dart
+++ b/pkg/compiler/lib/src/hash/sha1.dart
@@ -11,33 +11,55 @@ library sha1;
import 'dart:math' show pow;
import 'dart:convert';
-/// Returns the base64-encoded SHA-1 hash of the utf-8 bytes of [input].
-String hashOfString(String input) {
- Hash hasher = new SHA1();
- hasher.add(const Utf8Encoder().convert(input));
- return _bytesToBase64(hasher.close());
-}
+import '../io/code_output.dart' show CodeOutputListener;
-/**
- * Converts a list of bytes into a Base 64 encoded string.
- *
- * The list can be any list of integers in the range 0..255,
- * for example a message digest.
- *
- * If [addLineSeparator] is true, the resulting string will be
- * broken into lines of 76 characters, separated by "\r\n".
- *
- * If [urlSafe] is true, the result is URL and filename safe.
- *
- * Based on [RFC 4648](http://tools.ietf.org/html/rfc4648)
- *
- */
-String _bytesToBase64(List<int> bytes,
- {bool urlSafe : false,
- bool addLineSeparator : false}) {
- return _CryptoUtils.bytesToBase64(bytes,
- urlSafe,
- addLineSeparator);
+class Hasher implements CodeOutputListener {
+ Hash _hasher = new SHA1();
+ String _hashString;
+
+ @override
+ void onDone(int length) {
+ // Do nothing.
+ }
+
+ @override
+ void onText(String text) {
+ if (_hasher != null) {
+ _hasher.add(const Utf8Encoder().convert(text));
+ }
+ }
+
+ /// Returns the base64-encoded SHA-1 hash of the utf-8 bytes of the output
+ /// text.
+ String getHash() {
+ if (_hashString == null) {
+ _hashString = _bytesToBase64(_hasher.close());
+ _hasher = null;
+ }
+ return _hashString;
+ }
+
+ /**
+ * Converts a list of bytes into a Base 64 encoded string.
+ *
+ * The list can be any list of integers in the range 0..255,
+ * for example a message digest.
+ *
+ * If [addLineSeparator] is true, the resulting string will be
+ * broken into lines of 76 characters, separated by "\r\n".
+ *
+ * If [urlSafe] is true, the result is URL and filename safe.
+ *
+ * Based on [RFC 4648](http://tools.ietf.org/html/rfc4648)
+ *
+ */
+ String _bytesToBase64(List<int> bytes,
+ {bool urlSafe : false,
+ bool addLineSeparator : false}) {
+ return _CryptoUtils.bytesToBase64(bytes,
+ urlSafe,
+ addLineSeparator);
+ }
}
« no previous file with comments | « pkg/compiler/lib/src/deferred_load.dart ('k') | pkg/compiler/lib/src/io/code_output.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698