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>,
)
| 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<'_> { |
nothing calls this directly
no test coverage detected