Decrypt the payload if the record is encrypted. `epoch` must come from the on-disk segment preamble, not from the current in-memory key. `preamble_bytes` must be the same 16-byte preamble that was used as part of the AAD during encryption.
(
&self,
epoch: &[u8; 4],
preamble_bytes: Option<&[u8; PREAMBLE_SIZE]>,
encryption_key: Option<&crate::crypto::WalEncryptionKey>,
)
| 104 | /// current in-memory key. `preamble_bytes` must be the same 16-byte |
| 105 | /// preamble that was used as part of the AAD during encryption. |
| 106 | pub fn decrypt_payload( |
| 107 | &self, |
| 108 | epoch: &[u8; 4], |
| 109 | preamble_bytes: Option<&[u8; PREAMBLE_SIZE]>, |
| 110 | encryption_key: Option<&crate::crypto::WalEncryptionKey>, |
| 111 | ) -> Result<Vec<u8>> { |
| 112 | if !self.is_encrypted() { |
| 113 | return Ok(self.payload.clone()); |
| 114 | } |
| 115 | |
| 116 | let key = encryption_key.ok_or_else(|| WalError::EncryptionError { |
| 117 | detail: "record is encrypted but no decryption key provided".into(), |
| 118 | })?; |
| 119 | |
| 120 | let mut aad_header = self.header; |
| 121 | aad_header.record_type &= !ENCRYPTED_FLAG; |
| 122 | aad_header.payload_len = 0; |
| 123 | aad_header.crc32c = 0; |
| 124 | let header_bytes = aad_header.to_bytes(); |
| 125 | let aad = build_aad(preamble_bytes, &header_bytes); |
| 126 | |
| 127 | key.decrypt_aad(epoch, self.header.lsn, &aad, &self.payload) |
| 128 | } |
| 129 | |
| 130 | /// Decrypt the payload using a key ring (supports dual-key rotation). |
| 131 | /// |
nothing calls this directly
no test coverage detected