Skip to main content

aven_protocol/
context.rs

1use std::fmt;
2
3use zeroize::Zeroize;
4
5/// Public cryptographic context supplied by the vault owner.
6#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7pub struct LocalSharedStatePackageContext {
8    pub vault_id: [u8; 32],
9    pub generation_id: [u8; 32],
10}
11
12/// A generation secret supplied by a secure-store boundary.
13///
14/// Protocol never persists this value. Debug output is redacted and owned bytes are
15/// zeroized on drop. Callers remain responsible for protected durable storage.
16pub struct LocalSharedStatePackageKey([u8; 32]);
17
18impl Clone for LocalSharedStatePackageKey {
19    fn clone(&self) -> Self {
20        Self(self.0)
21    }
22}
23
24impl LocalSharedStatePackageKey {
25    pub fn new(bytes: [u8; 32]) -> Self {
26        Self(bytes)
27    }
28
29    /// Borrows key bytes only for persistence at a host protected-store boundary.
30    ///
31    /// Callers must not place these bytes in SQLite, settings, logs, exports, or
32    /// ordinary backups.
33    pub fn protected_storage_bytes(&self) -> &[u8; 32] {
34        &self.0
35    }
36}
37
38impl fmt::Debug for LocalSharedStatePackageKey {
39    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
40        formatter.write_str("LocalSharedStatePackageKey([REDACTED])")
41    }
42}
43
44impl Drop for LocalSharedStatePackageKey {
45    fn drop(&mut self) {
46        self.0.zeroize();
47    }
48}