Ensure unrecognized prefixes map to ParseError::NotZcash

This commit is contained in:
Kris Nuttycombe 2021-12-07 12:08:57 -07:00
parent 4e906508ae
commit fd786f28b7
2 changed files with 10 additions and 3 deletions

View File

@ -20,6 +20,7 @@ impl From<unified::ParseError> for ParseError {
fn from(e: unified::ParseError) -> Self {
match e {
unified::ParseError::InvalidEncoding(_) => Self::InvalidEncoding,
unified::ParseError::UnknownPrefix(_) => Self::NotZcash,
_ => Self::Unified(e),
}
}
@ -57,7 +58,7 @@ impl FromStr for ZcashAddress {
// allow decoding to fall through to Sapling/Transparent
}
Err(e) => {
return Err(ParseError::Unified(e));
return Err(ParseError::from(e));
}
}
@ -228,6 +229,12 @@ mod tests {
kind: AddressKind::Unified(unified::Address(vec![unified::address::Receiver::Sapling([0; 43])])),
},
);
let badencoded = "uinvalid1ck5navqwcng43gvsxwrxsplc22p7uzlcag6qfa0zh09e87efq6rq8wsnv25umqjjravw70rl994n5ueuhza2fghge5gl7zrl2qp6cwmp";
assert_eq!(
badencoded.parse::<ZcashAddress>(),
Err(ParseError::NotZcash)
);
}
#[test]

View File

@ -337,8 +337,8 @@ pub trait Encoding: private::SealedContainer {
/// recommended by ZIP 316.
///
/// This function will return an error in the case that the following ZIP 316
/// invariants concerning the composition of a unified container are
/// violated:
/// invariants concerning the composition of a unified container are
/// violated:
/// * the item list may not contain two items having the same typecode
/// * the item list may not contain only a single transparent item
fn try_from_items_preserving_order(items: Vec<Self::Item>) -> Result<Self, ParseError> {