@@ -20,7 +20,7 @@ struct UnknownOutputFormat {
2020}
2121
2222#[ derive( Copy , Clone , ValueEnum , Debug ) ]
23- enum ChecksumAlgorithm {
23+ enum FileHash {
2424 MD5 ,
2525 SHA1 ,
2626 SHA256 ,
@@ -57,10 +57,10 @@ struct FindOption {
5757 total_size : bool ,
5858 #[ clap( long, help = "get PE file version if available" ) ]
5959 get_version : bool ,
60- #[ clap( long, help = "get checksum for file as upper hex string(this may take heavy cpu usage)" ) ]
61- checksum : bool ,
62- #[ clap( long, help = "checksum algorithm(default: sha256)" , value_enum) ]
63- checksum_alg : Option < ChecksumAlgorithm > ,
60+ #[ clap( long, help = "get hash for file as upper hex string(this may take heavy cpu usage)" ) ]
61+ hash : bool ,
62+ #[ clap( long, help = "hash algorithm(default: sha256)" , value_enum) ]
63+ hash_alg : Option < FileHash > ,
6464}
6565
6666enum RecordWriter < T >
9696 . as_str ( ) ,
9797 record. file_version . unwrap_or ( String :: new ( ) ) . as_str ( ) ,
9898 record. product_version . unwrap_or ( String :: new ( ) ) . as_str ( ) ,
99- record. checksum . unwrap_or ( String :: new ( ) ) . as_str ( )
99+ record. hash . unwrap_or ( String :: new ( ) ) . as_str ( )
100100 ] ) ?;
101101 }
102102 Self :: NdJson ( v) => {
@@ -123,7 +123,7 @@ where
123123 "last_modified" ,
124124 "file_version" ,
125125 "product_version" ,
126- "checksum " ,
126+ "hash " ,
127127 ] ) ?;
128128 }
129129 Self :: NdJson ( _) => { } ,
@@ -142,7 +142,7 @@ struct FileRecord {
142142 link_target : Option < String > ,
143143 file_version : Option < String > ,
144144 product_version : Option < String > ,
145- checksum : Option < String > ,
145+ hash : Option < String > ,
146146}
147147
148148enum OutputStream {
@@ -178,7 +178,7 @@ struct FindContext<'a> {
178178 dir_only : bool ,
179179 output_total : bool ,
180180 get_version : bool ,
181- checksum : Option < ChecksumAlgorithm > ,
181+ hash : Option < FileHash > ,
182182}
183183
184184fn create_record_writer (
@@ -222,8 +222,8 @@ impl<'a> FindContext<'a> {
222222 let max_depth = opts. max_depth . parse :: < i32 > ( ) ?;
223223 let output_total = opts. total_size ;
224224 let dir_only = opts. dir_only ;
225- let checksum = if opts. checksum {
226- Some ( opts. checksum_alg . unwrap_or ( ChecksumAlgorithm :: SHA256 ) )
225+ let hash = if opts. hash {
226+ Some ( opts. hash_alg . unwrap_or ( FileHash :: SHA256 ) )
227227 } else {
228228 None
229229 } ;
@@ -239,7 +239,7 @@ impl<'a> FindContext<'a> {
239239 output_total : output_total,
240240 dir_only : dir_only,
241241 get_version : opts. get_version ,
242- checksum : checksum ,
242+ hash : hash ,
243243 } )
244244 }
245245 pub fn with_path ( mut self , new_path : & std:: path:: Path ) -> Self {
@@ -297,7 +297,7 @@ fn bytes_to_upper_hex_string(data: &[u8]) -> String {
297297
298298}
299299
300- fn get_checksum_from_filehandle < T : Digest > ( mut f : File , mut d : T ) -> Result < String >
300+ fn get_hash_from_filehandle < T : Digest > ( mut f : File , mut d : T ) -> Result < String >
301301{
302302 let mut buf = [ 0u8 ; 1024 ] ;
303303 loop {
@@ -318,17 +318,17 @@ fn get_checksum_from_filehandle<T: Digest>(mut f: File, mut d: T) -> Result<Stri
318318 // Ok(base64::encode(&data))
319319}
320320
321- fn get_checksum_from_path ( path : & std:: path:: Path , alg : & ChecksumAlgorithm ) -> Result < String > {
321+ fn get_hash_from_path ( path : & std:: path:: Path , alg : & FileHash ) -> Result < String > {
322322 let f = File :: open ( path) ?;
323323 let base64str = match alg {
324- ChecksumAlgorithm :: MD5 => {
325- get_checksum_from_filehandle :: < Md5 > ( f, md5:: Digest :: new ( ) )
324+ FileHash :: MD5 => {
325+ get_hash_from_filehandle :: < Md5 > ( f, md5:: Digest :: new ( ) )
326326 } ,
327- ChecksumAlgorithm :: SHA1 => {
328- get_checksum_from_filehandle :: < Sha1 > ( f, sha1:: Digest :: new ( ) )
327+ FileHash :: SHA1 => {
328+ get_hash_from_filehandle :: < Sha1 > ( f, sha1:: Digest :: new ( ) )
329329 } ,
330- ChecksumAlgorithm :: SHA256 => {
331- get_checksum_from_filehandle :: < Sha256 > ( f, sha2digest:: new ( ) )
330+ FileHash :: SHA256 => {
331+ get_hash_from_filehandle :: < Sha256 > ( f, sha2digest:: new ( ) )
332332 }
333333 } ;
334334 let base64str = match base64str {
@@ -375,8 +375,8 @@ fn output_symlink_info<'a>(
375375 let ( file_version, product_version) = if ctx. get_version {
376376 pe:: read_version_from_dll ( path) . unwrap_or ( ( None , None ) )
377377 } else { ( None , None ) } ;
378- let checksum = if let Some ( alg) = ctx. checksum . as_ref ( ) {
379- get_checksum_from_path ( path, & alg) . map_or_else ( |_| None , |v| Some ( v) )
378+ let hash = if let Some ( alg) = ctx. hash . as_ref ( ) {
379+ get_hash_from_path ( path, & alg) . map_or_else ( |_| None , |v| Some ( v) )
380380 } else {
381381 None
382382 } ;
@@ -389,7 +389,7 @@ fn output_symlink_info<'a>(
389389 modified,
390390 file_version,
391391 product_version,
392- checksum
392+ hash
393393 ) ?;
394394 }
395395 Ok ( ( ctx, len) )
@@ -424,8 +424,8 @@ fn output_symlink_file_info<'a>(
424424 let ( file_version, product_version) = if ctx. get_version {
425425 pe:: read_version_from_dll ( path) . unwrap_or ( ( None , None ) )
426426 } else { ( None , None ) } ;
427- let checksum = if let Some ( alg) = ctx. checksum {
428- match get_checksum_from_path ( path, & alg) {
427+ let hash = if let Some ( alg) = ctx. hash {
428+ match get_hash_from_path ( path, & alg) {
429429 Ok ( v) => Some ( v) ,
430430 Err ( _) => None ,
431431 }
@@ -440,7 +440,7 @@ fn output_symlink_file_info<'a>(
440440 modified,
441441 file_version,
442442 product_version,
443- checksum ) ?;
443+ hash ) ?;
444444 }
445445 Ok ( ( ctx. with_path ( parent. as_path ( ) ) , l. unwrap_or ( 0 ) ) )
446446}
@@ -483,8 +483,8 @@ fn output_file_info<'a>(
483483 } ;
484484 if !ctx. dir_only {
485485 let ( file_version, product_version) = pe:: read_version_from_dll ( path) . unwrap_or ( ( None , None ) ) ;
486- let checksum = if let Some ( alg) = ctx. checksum {
487- get_checksum_from_path ( path, & alg) . map_or_else ( |_| None , |v| Some ( v) )
486+ let hash = if let Some ( alg) = ctx. hash {
487+ get_hash_from_path ( path, & alg) . map_or_else ( |_| None , |v| Some ( v) )
488488 } else {
489489 None
490490 } ;
@@ -497,7 +497,7 @@ fn output_file_info<'a>(
497497 modified,
498498 file_version,
499499 product_version,
500- checksum
500+ hash
501501 ) ?;
502502 }
503503 Ok ( ( ctx. with_path ( parent. as_path ( ) ) , len. unwrap_or ( 0 ) ) )
@@ -531,7 +531,7 @@ fn write_record<T>(
531531 last_write : Option < std:: time:: SystemTime > ,
532532 file_version : Option < String > ,
533533 product_version : Option < String > ,
534- checksum : Option < String >
534+ hash : Option < String >
535535) -> Result < ( ) >
536536where
537537 T : std:: io:: Write ,
@@ -551,7 +551,7 @@ where
551551 last_modified : Some ( ststr) ,
552552 file_version : file_version,
553553 product_version : product_version,
554- checksum : checksum ,
554+ hash : hash ,
555555 } ) ?;
556556 Ok ( ( ) )
557557}
0 commit comments