oxabl_cache_crypto/
keys.rs1use crate::domain::{CTX_LOOKUP, CTX_RECORD, CTX_SEGMENT};
4use crate::error::Result;
5use crate::random;
6use crate::secret::secret_key;
7
8secret_key!(
9 RootKey
11);
12secret_key!(
13 LookupKey
15);
16secret_key!(
17 SegmentKey
19);
20secret_key!(
21 RecordKey
23);
24
25impl RootKey {
26 pub fn generate() -> Result<Self> {
28 random::array().map(Self)
29 }
30
31 pub fn lookup_key(&self) -> LookupKey {
32 LookupKey(blake3::derive_key(CTX_LOOKUP, &self.0))
33 }
34
35 pub fn segment_key(&self) -> SegmentKey {
36 SegmentKey(blake3::derive_key(CTX_SEGMENT, &self.0))
37 }
38
39 pub fn record_key(&self) -> RecordKey {
40 RecordKey(blake3::derive_key(CTX_RECORD, &self.0))
41 }
42}