mirror of
https://github.com/mikedilger/nip44.git
synced 2026-07-04 05:57:29 +00:00
Fix a buffer length panic in decryption
This commit is contained in:
@@ -165,6 +165,9 @@ pub fn decrypt(conversation_key: &[u8; 32], base64_ciphertext: &str) -> Result<S
|
||||
let mut cipher = ChaCha20::new(&keys.encryption().into(), &keys.nonce().into());
|
||||
cipher.apply_keystream(&mut buffer);
|
||||
let unpadded_len = u16::from_be_bytes(buffer[0..2].try_into().unwrap()) as usize;
|
||||
if buffer.len() < 2 + unpadded_len {
|
||||
return Err(Error::InvalidPadding);
|
||||
}
|
||||
let unpadded = &buffer[2..2 + unpadded_len];
|
||||
if unpadded.is_empty() {
|
||||
return Err(Error::MessageIsEmpty);
|
||||
|
||||
Reference in New Issue
Block a user