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.rs | |
| parent | acd9b487c189d7f82ae9187f0fffd0607478abc4 (diff) | |
Use input files for binary input and add utilities for hex encoding
Diffstat (limited to 'src/cmd.rs')
| -rw-r--r-- | src/cmd.rs | 22 |
1 files changed, 21 insertions, 1 deletions
@@ -3,11 +3,17 @@ pub mod address; pub mod export; pub mod hash; +pub mod hex; pub mod new; pub mod sign; use crate::{account::PrivateKey, hdk, mnemonic::Mnemonic}; use anyhow::Result; +use std::{ + fs, + io::{self, Read as _}, + path::Path, +}; use structopt::StructOpt; /// Shared account options. @@ -50,8 +56,22 @@ impl AccountOptions { fn permissive_hex(s: &str) -> Result<Box<[u8]>> { let trimmed = s.chars().filter(|c| !c.is_whitespace()).collect::<String>(); let hex_string = trimmed.strip_prefix("0x").unwrap_or(&trimmed); - let bytes = hex::decode(&hex_string)?; + let bytes = ::hex::decode(&hex_string)?; // NOTE: Use a boxed slice instead of a `Vec` as the former has special // scemantics with `structopt`. Ok(bytes.into_boxed_slice()) } + +/// Read input for the specified path with `-` used to signify standard in. +fn read_input(input: &Path) -> Result<Vec<u8>> { + let data = match input.to_str() { + Some("-") => { + let mut buf = Vec::new(); + io::stdin().read_to_end(&mut buf)?; + buf + } + _ => fs::read(&input)?, + }; + + Ok(data) +} |
