oxabl_cache_crypto/
dictionary_pointer.rs1use oxabl_cache_format::{CacheId, DictionaryPointer, SegmentId};
4
5use crate::domain::{SIG_DICTIONARY, prefixed};
6use crate::error::{Error, Result};
7use crate::identity::Identity;
8use crate::roster_verify::VerifiedRoster;
9use crate::signing;
10
11pub fn sign_pointer(
13 signer: &Identity,
14 cache_id: CacheId,
15 epoch: u32,
16 version: u64,
17 dict_segment_id: SegmentId,
18) -> DictionaryPointer {
19 let mut pointer = DictionaryPointer {
20 cache_id,
21 epoch,
22 version,
23 dict_segment_id,
24 signer: signer.signing_public(),
25 signature: [0; 64],
26 };
27 pointer.signature = signer.sign(&prefixed(SIG_DICTIONARY, &pointer.signed_bytes()));
28 pointer
29}
30
31pub fn verify_pointer(bytes: &[u8], roster: &VerifiedRoster) -> Result<DictionaryPointer> {
34 let pointer = DictionaryPointer::decode(bytes)?;
35 if pointer.cache_id != roster.cache_id() || pointer.epoch != roster.epoch() {
36 return Err(Error::Mismatch("dictionary pointer cache or epoch"));
37 }
38 signing::verify(
39 &pointer.signer,
40 &prefixed(SIG_DICTIONARY, &pointer.signed_bytes()),
41 &pointer.signature,
42 )?;
43 if !roster.is_ci_or_owner_key(&pointer.signer) {
44 return Err(Error::SignerNotAccepted);
45 }
46 Ok(pointer)
47}