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

Method set_encryption_ring

nodedb-wal/src/writer.rs:191–208  ·  view source on GitHub ↗

Set the key ring directly (for key rotation with dual-key reads). Writes the 16-byte WAL segment preamble at the current file offset. Must be called before the first `append`. Calling it after records have already been written to this file returns an error.

(&mut self, ring: crate::crypto::KeyRing)

Source from the content-addressed store, hash-verified

189 /// Must be called before the first `append`. Calling it after records
190 /// have already been written to this file returns an error.
191 pub fn set_encryption_ring(&mut self, ring: crate::crypto::KeyRing) -> Result<()> {
192 if self.file_offset != 0 || !self.buffer.is_empty() {
193 return Err(WalError::EncryptionError {
194 detail: "set_encryption_ring must be called before writing any records".into(),
195 });
196 }
197 let epoch = *ring.current().epoch();
198 let preamble = SegmentPreamble::new_wal(epoch);
199 let preamble_bytes = preamble.to_bytes();
200
201 // Write preamble into the buffer so it gets flushed with the first
202 // record batch (or on the next sync).
203 self.buffer.write(&preamble_bytes);
204
205 self.encryption_ring = Some(ring);
206 self.segment_preamble = Some(preamble);
207 Ok(())
208 }
209
210 /// Access the key ring (for decryption during replay).
211 pub fn encryption_ring(&self) -> Option<&crate::crypto::KeyRing> {

Callers 2

set_encryption_keyMethod · 0.45

Calls 5

is_emptyMethod · 0.45
epochMethod · 0.45
currentMethod · 0.45
to_bytesMethod · 0.45
writeMethod · 0.45

Tested by 1