Set the encryption key for WAL-at-rest encryption. Writes the 16-byte WAL preamble at the head of the segment. Must be called before the first `append`.
(&mut self, key: crate::crypto::WalEncryptionKey)
| 126 | /// Writes the 16-byte WAL preamble at the head of the segment. |
| 127 | /// Must be called before the first `append`. |
| 128 | pub fn set_encryption_key(&mut self, key: crate::crypto::WalEncryptionKey) -> Result<()> { |
| 129 | if self.file_offset != 0 || !self.buffer.is_empty() { |
| 130 | return Err(WalError::EncryptionError { |
| 131 | detail: "set_encryption_key must be called before writing any records".into(), |
| 132 | }); |
| 133 | } |
| 134 | let epoch = *key.epoch(); |
| 135 | let preamble = crate::preamble::SegmentPreamble::new_wal(epoch); |
| 136 | self.buffer.write(&preamble.to_bytes()); |
| 137 | self.segment_preamble = Some(preamble); |
| 138 | self.encryption_key = Some(key); |
| 139 | Ok(()) |
| 140 | } |
| 141 | |
| 142 | /// Append a record to the in-memory buffer. Returns the assigned LSN. |
| 143 | /// |