Skip to main content

into_sized_array

Function into_sized_array 

Source
pub fn into_sized_array<const SIZE: usize, E, T>(
    bytes: T,
    into_error: impl Fn(TryFromSliceError, usize) -> E,
) -> Result<[u8; SIZE], E>
where T: Deref<Target = Bytes>,
Expand description

Turn any Bytes-like structure into a sized slice. Useful for crypto operation requiring operands with specific bytes sizes. For example:

§```

§let public_key: [u8; ed25519::PublicKey::SIZE] = into_sized_array(vkey, |error, expected| {

§InvalidVKeyWitness::InvalidKeySize { error, expected }

§})?;

§```