aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/hash.rs
blob: 4a650ff04aed148577ea045f5b173fd5b1255972 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//! Module implementing the `hash` subcommand for `keccak256` hashing data.

use crate::cmd;
use anyhow::Result;
use hdwallet::hash;
use std::path::PathBuf;
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
pub struct Options {
    /// 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 = cmd::read_input(&options.data)?;
    println!("0x{}", hex::encode(hash::keccak256(data)));
    Ok(())
}