diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2021-05-13 05:35:37 +0000 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2021-05-13 05:35:37 +0000 |
| commit | 223cd670577c55d65762a056782124dc4c905f04 (patch) | |
| tree | 1bc0cf9010c7af1c3ff2732856360b88c289b43e /src/cmd/hash.rs | |
| parent | acd9b487c189d7f82ae9187f0fffd0607478abc4 (diff) | |
Use input files for binary input and add utilities for hex encoding
Diffstat (limited to 'src/cmd/hash.rs')
| -rw-r--r-- | src/cmd/hash.rs | 28 |
1 files changed, 3 insertions, 25 deletions
diff --git a/src/cmd/hash.rs b/src/cmd/hash.rs index 78f33cb..aade76b 100644 --- a/src/cmd/hash.rs +++ b/src/cmd/hash.rs @@ -2,40 +2,18 @@ use crate::{cmd, hash}; use anyhow::Result; -use std::{ - fs, - io::{self, Read}, - path::PathBuf, - str, -}; +use std::path::PathBuf; use structopt::StructOpt; #[derive(Debug, StructOpt)] pub struct Options { - /// The data is hexidecimal encoded. - #[structopt(short, long)] - hex: bool, - /// Path to the data to hash. Use `-` for standard in. #[structopt(name = "DATA", default_value = "-")] data: PathBuf, } pub fn run(options: Options) -> Result<()> { - let data = match options.data.to_str() { - Some("-") => { - let mut buf = Vec::new(); - io::stdin().read_to_end(&mut buf)?; - buf - } - _ => fs::read(&options.data)?, - }; - let bytes = if options.hex { - cmd::permissive_hex(str::from_utf8(&data)?)? - } else { - data.into_boxed_slice() - }; - - println!("0x{}", hex::encode(hash::keccak256(bytes))); + let data = cmd::read_input(&options.data)?; + println!("0x{}", hex::encode(hash::keccak256(data))); Ok(()) } |
