MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / open_with_kek

Method open_with_kek

nodedb-columnar/src/reader/segment_reader.rs:60–74  ·  view source on GitHub ↗

Open a segment with optional at-rest decryption. - `kek = None` → requires a plaintext (`NDBS`) segment; returns `Err(MissingKek)` if the blob starts with `SEGC`. - `kek = Some(key)` → requires an encrypted (`SEGC`) segment; decrypts the blob, then parses the inner plaintext. Returns `Err(KekRequired)` if the blob starts with `NDBS`.

(
        blob: &[u8],
        kek: Option<&nodedb_wal::crypto::WalEncryptionKey>,
    )

Source from the content-addressed store, hash-verified

58 /// the blob, then parses the inner plaintext. Returns `Err(KekRequired)`
59 /// if the blob starts with `NDBS`.
60 pub fn open_with_kek(
61 blob: &[u8],
62 kek: Option<&nodedb_wal::crypto::WalEncryptionKey>,
63 ) -> Result<Self, ColumnarError> {
64 let is_encrypted = blob.len() >= 4 && blob[0..4] == crate::encrypt::SEGC_MAGIC;
65 if is_encrypted {
66 let key = kek.ok_or(ColumnarError::MissingKek)?;
67 let plaintext = crate::encrypt::decrypt_segment(key, blob)?;
68 Self::from_plaintext(plaintext)
69 } else if kek.is_some() {
70 Err(ColumnarError::KekRequired)
71 } else {
72 Self::from_plaintext(blob.to_vec())
73 }
74 }
75
76 /// Borrow a `SegmentReader` over the owned plaintext bytes.
77 pub fn reader(&self) -> SegmentReader<'_> {

Callers

nothing calls this directly

Calls 3

decrypt_segmentFunction · 0.50
lenMethod · 0.45
to_vecMethod · 0.45

Tested by

no test coverage detected