Ensure unrecognized prefixes map to ParseError::NotZcash
This commit is contained in:
parent
4e906508ae
commit
fd786f28b7
|
@ -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]
|
||||
|
|
|
@ -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> {
|
||||
|
|
Loading…
Reference in New Issue