subkey: only decode hex if requested, CLI 0x prefixed hex for all stdout (#13258)

* Only decode hex if requested

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Cleanup code

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add some tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add license

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Docs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Clippy

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* bump version, breaking (tiny) change in output.

* Move integration tests to own folder

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Dan Shields <nukemandan@protonmail.com>
This commit is contained in:
Oliver Tale-Yazdi
2023-02-13 17:09:34 +01:00
committed by GitHub
parent d73348b2ca
commit eeb3e95701
10 changed files with 413 additions and 54 deletions
+1 -18
View File
@@ -31,7 +31,7 @@ use sp_core::{
Pair,
};
use sp_runtime::{traits::IdentifyAccount, MultiSigner};
use std::{io::Read, path::PathBuf};
use std::path::PathBuf;
/// Public key type for Runtime
pub type PublicFor<P> = <P as sp_core::Pair>::Public;
@@ -273,23 +273,6 @@ where
format!("0x{}", HexDisplay::from(&public_key.into().into_account().as_ref()))
}
/// checks if message is Some, otherwise reads message from stdin and optionally decodes hex
pub fn read_message(msg: Option<&String>, should_decode: bool) -> Result<Vec<u8>, Error> {
let mut message = vec![];
match msg {
Some(m) => {
message = array_bytes::hex2bytes(m.as_str())?;
},
None => {
std::io::stdin().lock().read_to_end(&mut message)?;
if should_decode {
message = array_bytes::hex2bytes(array_bytes::hex_bytes2hex_str(&message)?)?;
}
},
}
Ok(message)
}
/// Allows for calling $method with appropriate crypto impl.
#[macro_export]
macro_rules! with_crypto_scheme {