zcash_address: Fix padding and F4Jumble positions in Address::to_bytes

These need to be applied to the entire UA encoding, not to the encoding
of each individual receiver.
This commit is contained in:
Jack Grigg 2021-05-25 21:23:15 +01:00
parent ff8695de03
commit ff94f66d8e
1 changed files with 7 additions and 7 deletions

View File

@ -120,23 +120,23 @@ impl TryFrom<&[u8]> for Address {
impl Address {
/// Returns the raw encoding of this Unified Address.
pub(crate) fn to_bytes(&self) -> Vec<u8> {
self.0
let encoded: Vec<_> = self
.0
.iter()
.flat_map(|receiver| {
let addr = receiver.addr();
// Holds by construction.
assert!(addr.len() < 256);
let encoded: Vec<_> = iter::empty()
iter::empty()
.chain(Some(receiver.typecode()))
.chain(Some(addr.len() as u8))
.chain(addr.into_iter().cloned())
.chain(iter::repeat(0).take(PADDING_LEN))
.collect();
f4jumble::f4jumble(&encoded).unwrap()
})
.collect()
.chain(iter::repeat(0).take(PADDING_LEN))
.collect();
f4jumble::f4jumble(&encoded).unwrap()
}
}