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

Unified Diff: example/hash.dart

Issue 1350833002: a more generic example (Closed) Base URL: git@github.com:dart-lang/crypto.git@master
Patch Set: fix error message 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: example/hash.dart
diff --git a/example/hash.dart b/example/hash.dart
new file mode 100644
index 0000000000000000000000000000000000000000..0f7900736820cd2ac3aa986c48634a7bb9824a67
--- /dev/null
+++ b/example/hash.dart
@@ -0,0 +1,48 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:io' show exit, File;
+import 'package:crypto/crypto.dart' show MD5, SHA1, SHA256, CryptoUtils;
+
+const USAGE = 'Usage: dart hash.dart <md5|sha1|sha256> <input_filename>';
+
+main(List<String> args) async {
+ if (args == null || args.length != 2) {
+ print(USAGE);
+ exit(1);
+ }
+
+ var hasher;
+
+ switch (args[0]) {
+ case 'md5':
+ hasher = new MD5();
+ break;
+ case 'sha1':
+ hasher = new SHA1();
+ break;
+ case 'sha256':
+ hasher = new SHA256();
+ break;
+ default:
+ print(USAGE);
+ exit(1);
+ }
+
+ var filename = args[1];
+ var input = new File(filename);
+
+ if (!input.existsSync()) {
+ print('File "$filename" does not exist.');
+ exit(1);
+ }
+
+ await for (var bytes in input.openRead()) {
+ hasher.add(bytes);
+ }
+
+ var hex = CryptoUtils.bytesToHex(hasher.close());
+
+ print(hex);
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698