Skip to content

Commit

Permalink
base: trim input, for ease of use
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Rigo committed Aug 23, 2024
1 parent 68dac0c commit f9badc4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/baseapp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ impl Applet for BaseIntApplet {
}

fn process(&self, val: Vec<u8>) -> Result<Vec<u8>> {
let val_trimmed = val.trim_ascii();
let int = if let Some(src) = self.source_radix {
BigUint::parse_bytes(&val, src).context("Could not convert input")?
BigUint::parse_bytes(&val_trimmed, src).context("Could not convert input")?
} else {
let int_str = String::from_utf8(val).context("Could not convert value to string")?;
let int_str = String::from_utf8(val_trimmed.to_vec())
.context("Could not convert value to string")?;
BigUint::from_str_with_radix(int_str.as_str())?
};
Ok(int.to_str_radix(self.target_radix).as_bytes().to_vec())
Expand Down

0 comments on commit f9badc4

Please sign in to comment.