diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2021-03-18 09:28:50 +0100 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2021-03-18 09:28:50 +0100 |
| commit | 789f4585504119de8e490aa12a8c02b649f24ee0 (patch) | |
| tree | ef2df8f30af6f06102b49555a308d77d9eae36ef /src/cmd.rs | |
| parent | 1ce0c196c10dc92977114279180ea714056c587d (diff) | |
added hashing command
Diffstat (limited to 'src/cmd.rs')
| -rw-r--r-- | src/cmd.rs | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -2,6 +2,7 @@ pub mod address; pub mod export; +pub mod hash; pub mod new; pub mod sign; @@ -43,3 +44,14 @@ impl AccountOptions { hdk::derive(seed, &path) } } + +/// Permissive hex encoding parsing, ignoring all whitespace and accepting bot +/// upper and lower-case string with an optional `0x` prefix. +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)?; + // NOTE: Use a boxed slice instead of a `Vec` as the former has special + // scemantics with `structopt`. + Ok(bytes.into_boxed_slice()) +} |
