//! Associated data that binds a ciphertext to its location (docs/02 "Envelope format"). use uuid::Uuid; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum ObjectType { Keyset, VaultKey, VaultMeta, ItemKey, Item, } impl ObjectType { fn tag(self) -> &'static str { match self { ObjectType::Keyset => "keyset", ObjectType::VaultKey => "vault-key", ObjectType::VaultMeta => "vault-meta", ObjectType::ItemKey => "item-key", ObjectType::Item => "item", } } } pub struct Aad; impl Aad { /// `"kestrove/v1/" || type || 0x00 || account || 0x00 || vault || 0x00 || item`. /// Absent ids are encoded as the nil UUID so the layout stays fixed. pub fn build(ty: ObjectType, account: Uuid, vault: Option, item: Option) -> Vec { let mut out = Vec::with_capacity(12 + 10 + 3 + 48); out.extend_from_slice(b"kestrove/v1/"); out.extend_from_slice(ty.tag().as_bytes()); for id in [account, vault.unwrap_or(Uuid::nil()), item.unwrap_or(Uuid::nil())] { out.push(0); out.extend_from_slice(id.as_bytes()); } out } }