Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Daira-Emma Hopwood <[email protected]>
  • Loading branch information
nuttycom and daira committed Apr 1, 2024
1 parent c842a7c commit 478f2e3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions components/zcash_address/src/kind/unified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,15 @@ impl MetadataItem {
"Expiry time must be a 64-bit little-endian value.".to_string(),

Check warning on line 241 in components/zcash_address/src/kind/unified.rs

View check run for this annotation

Codecov / codecov/patch

components/zcash_address/src/kind/unified.rs#L237-L241

Added lines #L237 - L241 were not covered by tests
)
}),
(R0, ExpiryHeight | ExpiryTime) => Err(ParseError::NotUnderstood(typecode.into())),
(R0 | R1, MustUnderstand(tc)) => Err(ParseError::NotUnderstood(tc)),

Check warning on line 245 in components/zcash_address/src/kind/unified.rs

View check run for this annotation

Codecov / codecov/patch

components/zcash_address/src/kind/unified.rs#L244-L245

Added lines #L244 - L245 were not covered by tests
// This implementation treats the 0xC0..OxFD range as unknown metadata for both R0 and
// R1, as no typecodes were specified in this range for R0 and were "reclaimed" as
// metadata codes by ZIP 316 at the time R1 was introduced.
(R0 | R1, Unknown(typecode)) => Ok(MetadataItem::Unknown {
typecode,
data: data.to_vec(),

Check warning on line 251 in components/zcash_address/src/kind/unified.rs

View check run for this annotation

Codecov / codecov/patch

components/zcash_address/src/kind/unified.rs#L249-L251

Added lines #L249 - L251 were not covered by tests
}),
(R0, ExpiryHeight | ExpiryTime) => Err(ParseError::NotUnderstood(typecode.into())),
}
}

Expand Down Expand Up @@ -502,6 +505,9 @@ pub(crate) mod private {
length
)));
}
// The "as usize" casts cannot change the values, because both
// cursor.position() and addr_end are u64 values <= buf.len()
// which is usize.
let data = &buf[cursor.position() as usize..addr_end as usize];
let result = match Typecode::try_from(typecode)? {
Typecode::Data(tc) => Item::Data(R::parse(tc, data)?),
Expand Down Expand Up @@ -564,9 +570,7 @@ pub(crate) mod private {
return Err(ParseError::InvalidTypecodeOrder);
} else if t_code == prev_code {
return Err(ParseError::DuplicateTypecode(t));
} else if t == Typecode::Data(DataTypecode::P2sh)
&& prev_code == Some(u32::from(DataTypecode::P2pkh))
{
} else if t == Typecode::P2SH && prev_code == Some(u32::from(DataTypecode::P2pkh)) {
// P2pkh and P2sh can only be in that order and next to each other,
// otherwise we would detect an out-of-order or duplicate typecode.
return Err(ParseError::BothP2phkAndP2sh);
Expand Down Expand Up @@ -604,7 +608,6 @@ pub trait Encoding: private::SealedContainer {
/// 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 transparent items (or no items)
/// * the item list may not contain both P2PKH and P2SH items.
fn try_from_items(
revision: Revision,
Expand Down

0 comments on commit 478f2e3

Please sign in to comment.