Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ctian1 committed Feb 13, 2024
1 parent bb831ce commit 1e48334
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions cli/src/commands/prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ enum Input {
HexBytes(Vec<u8>),
}

fn is_valid_hex_string(s: &str) -> bool {
if s.len() % 2 != 0 {
return false;
}
// All hex digits with optional 0x prefix
s.starts_with("0x") && s[2..].chars().all(|c| c.is_ascii_hexdigit())
|| s.chars().all(|c| c.is_ascii_hexdigit())
}

impl FromStr for Input {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
if PathBuf::from(s).exists() {
Ok(Input::FilePath(PathBuf::from(s)))
} else if s.len() % 2 == 0 {
if is_valid_hex_string(s) {
// Remove 0x prefix if present
let s = if s.starts_with("0x") {
s.strip_prefix("0x").unwrap()
Expand All @@ -42,6 +49,8 @@ impl FromStr for Input {
}
let bytes = hex::decode(s).map_err(|e| e.to_string())?;
Ok(Input::HexBytes(bytes))
} else if PathBuf::from(s).exists() {
Ok(Input::FilePath(PathBuf::from(s)))
} else {
Err("Input must be a valid file path or hex string.".to_string())
}
Expand All @@ -51,7 +60,7 @@ impl FromStr for Input {
#[derive(Parser)]
#[command(name = "prove", about = "Build and prove a program")]
pub struct ProveCmd {
#[clap(value_parser)]
#[clap(long, value_parser)]
input: Option<Input>,

#[clap(long, action)]
Expand Down

0 comments on commit 1e48334

Please sign in to comment.