aboutsummaryrefslogtreecommitdiff
path: root/src/cmd.rs
diff options
context:
space:
mode:
authorNicholas Rodrigues Lordello <[email protected]>2021-03-18 09:28:50 +0100
committerNicholas Rodrigues Lordello <[email protected]>2021-03-18 09:28:50 +0100
commit789f4585504119de8e490aa12a8c02b649f24ee0 (patch)
treeef2df8f30af6f06102b49555a308d77d9eae36ef /src/cmd.rs
parent1ce0c196c10dc92977114279180ea714056c587d (diff)
added hashing command
Diffstat (limited to 'src/cmd.rs')
-rw-r--r--src/cmd.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/cmd.rs b/src/cmd.rs
index 618c07c..63470a4 100644
--- a/src/cmd.rs
+++ b/src/cmd.rs
@@ -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())
+}