Skip to content

Commit

Permalink
rust: simplify bech32 hrp check
Browse files Browse the repository at this point in the history
  • Loading branch information
benma committed Oct 3, 2024
1 parent 90611db commit a66c417
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/rust/bitbox02-rust/src/hww/api/cardano/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ pub const ADDRESS_HASH_SIZE: usize = 28;
fn decode_shelley_payment_address(params: &params::Params, address: &str) -> Result<Vec<u8>, ()> {
let result =
bech32::primitives::decode::CheckedHrpstring::new::<bech32::Bech32>(address).or(Err(()))?;
// TODO: use `result.hrp().as_str()` once bech32 has a new release.
let hrp: String = result.hrp().char_iter().collect();
if hrp != params.bech32_hrp_payment {
let hrp = result.hrp();
if hrp.as_str() != params.bech32_hrp_payment {
return Err(());
}
let data: Vec<u8> = result.byte_iter().collect();
Expand Down
3 changes: 1 addition & 2 deletions src/rust/streaming-silent-payments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ fn decode_address(address: &str, expected_hrp: &str) -> Result<SilentPaymentAddr
.map_err(|_| ())?;

let hrp = decoded_addr.hrp();
let hrp: &str = hrp.as_str();
if hrp != expected_hrp {
if hrp.as_str() != expected_hrp {
return Err(());
}
let witness_version = decoded_addr.remove_witness_version().unwrap();
Expand Down

0 comments on commit a66c417

Please sign in to comment.