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

Method decrypt_payload

nodedb-wal/src/record/wal_record.rs:106–128  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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 ///

Callers

nothing calls this directly

Calls 5

build_aadFunction · 0.85
is_encryptedMethod · 0.80
decrypt_aadMethod · 0.80
cloneMethod · 0.45
to_bytesMethod · 0.45

Tested by

no test coverage detected