Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

subkey: fix hex message decoding and printing logic #13258

Merged
merged 8 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions client/cli/src/commands/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,17 @@ where
}

/// 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> {
pub fn read_message(msg: Option<&String>, decode_hex: bool) -> Result<Vec<u8>, Error> {
let mut message = vec![];
match msg {
Some(m) => {
message = array_bytes::hex2bytes(m.as_str())?;
if decode_hex {
message = array_bytes::hex2bytes(m.as_str())?;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If decode_hex == false, you will not have any message?

If you want to pass --message binary_data we would need to change message to Vec<u8> otherwise the binary data would be required to be valid utf8 data.

Copy link
Member Author

@ggwpez ggwpez Jan 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea… having binary data as CLI arg is rather uncommon. Clap interprets Vec<u8> not as raw data but as list of u8.
So i will change it to interpret --message as UTF8-non hex per default, as opposed to UTF8-hex before.

},
None => {
std::io::stdin().lock().read_to_end(&mut message)?;
if should_decode {
if decode_hex {
message = array_bytes::hex2bytes(array_bytes::hex_bytes2hex_str(&message)?)?;
}
},
Expand Down
7 changes: 4 additions & 3 deletions client/cli/src/commands/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ pub struct VerifyCmd {
/// If not given, you will be prompted for the URI.
uri: Option<String>,

/// Message to verify, if not provided you will be prompted to
/// pass the message via STDIN
/// Message to verify, if not provided you will be prompted to pass the message via STDIN.
///
/// The message is assumed to be raw bytes, unless `--hex` is specified.
#[arg(long)]
message: Option<String>,

/// The message on STDIN is hex-encoded data
/// The message is hex-encoded data.
#[arg(long)]
hex: bool,

Expand Down