oxabl_cache_crypto/
record_context.rs1use oxabl_cache_format::{CacheId, LookupId, Namespace};
4
5use crate::domain::{AD_RECORD, SIG_ENTRY, prefixed};
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub struct RecordContext {
10 pub cache_id: CacheId,
11 pub epoch: u32,
12 pub namespace: Namespace,
13 pub lookup_id: LookupId,
14}
15
16impl RecordContext {
17 fn tail(&self) -> Vec<u8> {
18 let mut out = Vec::with_capacity(16 + 4 + 1 + 32);
19 out.extend_from_slice(&self.cache_id.0);
20 out.extend_from_slice(&self.epoch.to_be_bytes());
21 out.push(self.namespace.to_u8());
22 out.extend_from_slice(&self.lookup_id.0);
23 out
24 }
25
26 pub(crate) fn associated_data(&self) -> Vec<u8> {
28 prefixed(AD_RECORD, &self.tail())
29 }
30
31 pub(crate) fn entry_transcript(&self, signed_payload: &[u8]) -> Vec<u8> {
33 let mut out = prefixed(SIG_ENTRY, &self.tail());
34 out.extend_from_slice(signed_payload);
35 out
36 }
37}