Skip to content

Commit

Permalink
Add VariableLengthSlice to work around a lifetime problem in users
Browse files Browse the repository at this point in the history
of `PrfExpand` (e.g. the `zip32` crate).

Signed-off-by: Daira-Emma Hopwood <daira@jacaranda.org>
  • Loading branch information
daira committed Feb 18, 2025
1 parent a0d5af6 commit 5987f26
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ and this library adheres to Rust's notion of
- `zcash_spec::PrfExpand::REGISTERED_ZIP32_CHILD` (for tagged ZIP 32 child
derivation).
- `zcash_spec::PrfExpand::ADHOC_ZIP32_CHILD` (renamed and retyped per ZIP 32).
- `zcash_spec::VariableLengthSlice`

### Changed
- `zcash_spec::PrfExpand::ORCHARD_ZIP32_CHILD` now has type
`PrfExpand<([u8; 32], [u8; 4], Option<(u8, &[u8])>)>` due to ZIP 32 changes.
`PrfExpand<([u8; 32], [u8; 4], Option<(u8, VariableLengthSlice)>)>` due to
ZIP 32 changes.

### Removed
- `zcash_spec::PrfExpand::ARBITRARY_ZIP32_CHILD` (use `ADHOC_ZIP32_CHILD`
Expand Down
5 changes: 4 additions & 1 deletion src/prf_expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ impl<T> PrfExpand<T> {
}
}

/// Marker type used for `PrfExpand` instantiations that permit a variable-length input.
pub struct VariableLengthSlice;

macro_rules! with_inputs {
($($arr:ident, $arrlen:ident),*) => {
#[allow(unused_parens)]
Expand Down Expand Up @@ -107,7 +110,7 @@ impl PrfExpand<([u8; 96], [u8; 32], [u8; 4])> {
}
with_inputs!(a, A, b, B, c, C);

impl PrfExpand<([u8; 32], [u8; 4], Option<(u8, &[u8])>)> {
impl PrfExpand<([u8; 32], [u8; 4], Option<(u8, VariableLengthSlice)>)> {
pub const ORCHARD_ZIP32_CHILD: Self = Self::new(0x81);
pub const ADHOC_ZIP32_CHILD: Self = Self::new(0xAB);
pub const REGISTERED_ZIP32_CHILD: Self = Self::new(0xAC);
Expand Down

0 comments on commit 5987f26

Please sign in to comment.