pub struct CollectionItem {
pub iv: u32,
pub ciphertext_and_tag: Vec<u8>,
}Expand description
Collection item containing an encrypted payload with its IV
Each item uses a unique counter-based IV derived from the collection’s IV counter. The ciphertext_and_tag contains the AES-GCM encrypted data with the authentication tag appended.
Fields§
§iv: u3224-bit IV counter value (1 to MAX_IV) This is used to reconstruct the 12-byte GCM nonce: [9 zeros][3-byte IV]
ciphertext_and_tag: Vec<u8>Ciphertext with authentication tag appended Format: [encrypted_data][auth_tag] Tag size depends on the symmetric cipher config in the collection manifest
Implementations§
Source§impl CollectionItem
impl CollectionItem
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Container framing: [IV (3B)][ciphertext][tag]
Use this format when the container (FLV/RTMP) provides the length. This is the minimal wire format for streaming scenarios.
Sourcepub fn to_nanotdf_payload_bytes(&self) -> Vec<u8> ⓘ
pub fn to_nanotdf_payload_bytes(&self) -> Vec<u8> ⓘ
NanoTDF payload framing: [length (3B)][IV (3B)][ciphertext][tag]
This is spec-compliant format with a 3-byte length prefix. Use this when you need a self-describing payload format.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_bytes(bytes: &[u8]) -> Result<Self>
Parse from container framing: [IV (3B)][ciphertext][tag]
The caller must know the total length from the container.
Sourcepub fn from_nanotdf_payload_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_nanotdf_payload_bytes(bytes: &[u8]) -> Result<Self>
Parse from NanoTDF payload framing: [length (3B)][IV (3B)][ciphertext][tag]
Reads the length prefix and validates the payload size.
Sourcepub fn read_from<R: Read>(reader: &mut R, total_len: usize) -> Result<Self>
pub fn read_from<R: Read>(reader: &mut R, total_len: usize) -> Result<Self>
Read from a reader using container framing
Reads exactly total_len bytes (IV + ciphertext + tag).
Sourcepub fn read_nanotdf_payload_from<R: Read>(reader: &mut R) -> Result<Self>
pub fn read_nanotdf_payload_from<R: Read>(reader: &mut R) -> Result<Self>
Read from a reader using NanoTDF payload framing
Reads the length prefix first, then the payload.
Sourcepub fn write_to<W: Write>(&self, writer: &mut W) -> Result<()>
pub fn write_to<W: Write>(&self, writer: &mut W) -> Result<()>
Write to a writer using container framing
Sourcepub fn write_nanotdf_payload_to<W: Write>(&self, writer: &mut W) -> Result<()>
pub fn write_nanotdf_payload_to<W: Write>(&self, writer: &mut W) -> Result<()>
Write to a writer using NanoTDF payload framing
Sourcepub fn container_size(&self) -> usize
pub fn container_size(&self) -> usize
Get the total size in container framing format
Sourcepub fn nanotdf_payload_size(&self) -> usize
pub fn nanotdf_payload_size(&self) -> usize
Get the total size in NanoTDF payload framing format
Sourcepub fn to_gcm_nonce(&self) -> [u8; 12]
pub fn to_gcm_nonce(&self) -> [u8; 12]
Convert the IV to a 12-byte GCM nonce
Per NanoTDF spec and JS SDK interop: [9 zero bytes][3-byte IV counter]