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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:io' show exit, File;
6 import 'package:crypto/crypto.dart' show MD5, SHA1, SHA256, CryptoUtils;
7
8 const USAGE = 'Usage: dart hash.dart <md5|sha1|sha256> <input_filename>';
9
10 main(List<String> args) async {
11 if (args == null || args.length != 2) {
12 print(USAGE);
13 exit(1);
14 }
15
16 var hasher;
17
18 switch (args[0]) {
19 case 'md5':
20 hasher = new MD5();
21 break;
22 case 'sha1':
23 hasher = new SHA1();
24 break;
25 case 'sha256':
26 hasher = new SHA256();
27 break;
28 default:
29 print(USAGE);
30 exit(1);
31 }
32
33 var filename = args[1];
34 var input = new File(filename);
35
36 if (!input.existsSync()) {
37 print('File "$filename" does not exist.');
38 exit(1);
39 }
40
41 await for (var bytes in input.openRead()) {
42 hasher.add(bytes);
43 }
44
45 var hex = CryptoUtils.bytesToHex(hasher.close());
46
47 print(hex);
48 }
OLDNEW
« 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