fix: report an over-long plaintext as MessageTooLong, not DecryptionFailed
This commit is contained in:
@@ -57,6 +57,8 @@ pub enum Error {
|
|||||||
UnsupportedVersion(u8),
|
UnsupportedVersion(u8),
|
||||||
/// A sealed box failed authentication: wrong key, wrong associated data, or tampered.
|
/// A sealed box failed authentication: wrong key, wrong associated data, or tampered.
|
||||||
DecryptionFailed,
|
DecryptionFailed,
|
||||||
|
/// The plaintext is longer than ChaCha20-Poly1305 allows (about 256 GiB).
|
||||||
|
MessageTooLong,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
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::NonContributory => f.write_str("X25519 value is a low-order point"),
|
||||||
Error::UnsupportedVersion(v) => write!(f, "sealed box version {v} is not supported"),
|
Error::UnsupportedVersion(v) => write!(f, "sealed box version {v} is not supported"),
|
||||||
Error::DecryptionFailed => f.write_str("sealed box could not be opened"),
|
Error::DecryptionFailed => f.write_str("sealed box could not be opened"),
|
||||||
|
Error::MessageTooLong => f.write_str("message is too long to seal"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -88,7 +88,7 @@ fn seal_inner(
|
|||||||
// ChaCha20-Poly1305 refuses only messages over 2^38 bytes; that is reported, not a panic.
|
// ChaCha20-Poly1305 refuses only messages over 2^38 bytes; that is reported, not a panic.
|
||||||
let tag = aead
|
let tag = aead
|
||||||
.encrypt_inout_detached(&nonce, &[VERSION], (&mut out[HEADER_LEN..]).into())
|
.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());
|
out.extend_from_slice(tag.as_slice());
|
||||||
Ok(out)
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user