I've been experimenting with the AEAD implementations, such as chacha20poly1305, by creating a vector of the appropriate size and putting the nonce, ciphertext, and tag into it. However, it's tricky to do this if one does not know the nonce or tag size until runtime, for example when giving the user the choice of AEADs. Would the project be receptive to adding a trait such as this to the implemented AEADs?
trait SealSize {
/// The length of a nonce.
type NonceSize: ArrayLength<u8>;
/// The length of the tag.
type TagSize: ArrayLength<u8>;
fn nonce_size() -> usize {
Self::NonceSize::to_usize()
}
fn tag_size() -> usize {
Self::TagSize::to_usize()
}
}
That would enable one to create the appropriate-sized buffers in, say a blanket implementation such as:
impl<D: Aead + SealSize> Seal for D {
fn seal(&self, msg: &[u8], aad: &[u8]) -> Result<Vec<u8>> {
// Generate a nonce.
let mut nonce = vec![0u8; Self::nonce_size()];
rand::thread_rng().fill(&mut nonce[..]);
// ...
}
}
I've been experimenting with the AEAD implementations, such as chacha20poly1305, by creating a vector of the appropriate size and putting the nonce, ciphertext, and tag into it. However, it's tricky to do this if one does not know the nonce or tag size until runtime, for example when giving the user the choice of AEADs. Would the project be receptive to adding a trait such as this to the implemented AEADs?
That would enable one to create the appropriate-sized buffers in, say a blanket implementation such as: