Initial scaffold for kestrove-core
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
//! 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<Uuid>, item: Option<Uuid>) -> Vec<u8> {
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user