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)
| 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> { |