fix: report an over-long plaintext as MessageTooLong, not DecryptionFailed

This commit is contained in:
2026-11-25 07:48:55 +01:00
parent e0c6d53a99
commit 853f59ca60
2 changed files with 4 additions and 1 deletions
+3
View File
@@ -57,6 +57,8 @@ pub enum Error {
UnsupportedVersion(u8),
/// A sealed box failed authentication: wrong key, wrong associated data, or tampered.
DecryptionFailed,
/// The plaintext is longer than ChaCha20-Poly1305 allows (about 256 GiB).
MessageTooLong,
}
impl fmt::Display for Error {
@@ -72,6 +74,7 @@ impl fmt::Display for Error {
Error::NonContributory => f.write_str("X25519 value is a low-order point"),
Error::UnsupportedVersion(v) => write!(f, "sealed box version {v} is not supported"),
Error::DecryptionFailed => f.write_str("sealed box could not be opened"),
Error::MessageTooLong => f.write_str("message is too long to seal"),
}
}
}
+1 -1
View File
@@ -88,7 +88,7 @@ fn seal_inner(
// ChaCha20-Poly1305 refuses only messages over 2^38 bytes; that is reported, not a panic.
let tag = aead
.encrypt_inout_detached(&nonce, &[VERSION], (&mut out[HEADER_LEN..]).into())
.map_err(|_| Error::DecryptionFailed)?;
.map_err(|_| Error::MessageTooLong)?;
out.extend_from_slice(tag.as_slice());
Ok(out)
}