22// for details. All rights reserved. Use of this source code is governed by a 
33// BSD-style license that can be found in the LICENSE file. 
44
5+ import  'dart:io'  show  exit, stderr;
56import  'dart:typed_data' ;
67
78import  'package:convert/convert.dart' ;
89import  'package:crypto/crypto.dart' ;
910
1011void  main (List <String > args) {
1112  Hash ?  function;
13+   int ?  customSize;
1214
1315  void  setFunction (Hash  newFunction, String  message) {
14-     if  (function !=  null ) throw  ArgumentError ('Hash function already set.' );
16+     if  (function !=  null ) {
17+       stderr.writeln ('Hash function already set.' );
18+       exit (1 );
19+     }
1520    function =  newFunction;
1621    print ('Using hash function $message ' );
1722  }
@@ -33,14 +38,22 @@ void main(List<String> args) {
3338      setFunction (sha512224, 'sha512/224' );
3439    } else  if  (arg ==  'sha512256' ) {
3540      setFunction (sha512256, 'sha512/256' );
41+     } else  if  (arg.startsWith ('--custom=' )) {
42+       customSize =  int .parse (arg.substring ('--custom=' .length));
3643    } else  {
37-       throw  ArgumentError ('Unknown argument: $arg ' );
44+       stderr.writeln ('Unknown argument: $arg ' );
45+       exit (1 );
3846    }
3947  }
4048  if  (function ==  null ) {
4149    setFunction (md5, 'md5' );
4250  }
4351
52+   if  (customSize !=  null ) {
53+     doIterationsChunk (function! , mb:  customSize, iterations:  1 , doPrint:  true );
54+     return ;
55+   }
56+ 
4457  // Warmup. 
4558  doIterationsChunk (function! , mb:  1 , iterations:  100 , doPrint:  false );
4659
0 commit comments