Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/aead/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod encrypt;
#[cfg(feature = "hlist")]
pub mod hlist;
mod nonce;
mod tree;

#[doc(inline)]
pub use aad::{Aad, IntoAad};
Expand All @@ -24,3 +25,8 @@ pub use decipher::{Decipher, DecipherVisitor, Decrypt, MapAccess, SeqAccess};
pub use encrypt::Encrypt;
#[doc(inline)]
pub use nonce::{Nonce, NonceGenerator, RandomNonceGenerator};
#[doc(inline)]
pub use tree::{
CipherTree, LeafOpener, PendingLeaf, TreeCipher, TreeDecipher, TreeMap, TreeMapAccess, TreeSeq,
TreeSeqAccess,
};
9 changes: 9 additions & 0 deletions packages/aead/src/nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ impl<const N: usize> Nonce<N> {
pub fn into_inner(self) -> [u8; N] {
self.0
}

/// Borrow the nonce as a fixed-size array. Unlike
/// [`into_inner`](Self::into_inner) this does not consume the nonce, so the
/// same nonce can be used for the AEAD call and then appended to the
/// ciphertext. Copy the result (`*nonce.as_array()`) when an owned array is
/// needed — no fallible slice conversion required.
pub fn as_array(&self) -> &[u8; N] {
&self.0
}
}

// TODO: Make this a trait that can be implemented for a cipher rather than an associated type on the Cipher
Expand Down
Loading