chacha20_poly1305: Move errors to error submodule
What changed, and why it matters
This commit is a simple internal code reorganization. It moves the existing 'Error' type into a new 'error' submodule and re-exports it so users can still access it the same way. There is no change to how encryption, decryption, or authentication works, and no security bug is fixed or introduced.
No security action needed. Treat as a normal API/organizational refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors the ChaCha20Poly1305 crate by relocating the public Error enum from the crate root into a new error submodule and re-exporting it with #[doc(no_inline)]. The enum variants, Display implementation, and std::error::Error implementation are copied verbatim. No functional logic in ChaCha20Poly1305, ChaCha20, or Poly1305 is modified.
Changed components
chacha20_poly1305/src/lib.rsInspect captured patch +31 / −26
diff --git a/chacha20_poly1305/src/lib.rs b/chacha20_poly1305/src/lib.rs
index ce20f458..4473f837 100644
--- a/chacha20_poly1305/src/lib.rs
+++ b/chacha20_poly1305/src/lib.rs
@@ -22,40 +22,16 @@ extern crate std;
pub mod chacha20;
pub mod poly1305;
-use core::fmt;
-
use chacha20::ChaCha20;
use poly1305::Poly1305;
pub use self::chacha20::{Key, Nonce};
+#[doc(no_inline)]
+pub use self::error::Error;
/// Zero array for padding slices.
const ZEROES: [u8; 16] = [0u8; 16];
-/// Errors encrypting and decrypting messages with `ChaCha20` and `Poly1305` authentication tags.
-#[derive(Copy, Clone, Debug, PartialEq, Eq)]
-pub enum Error {
- /// Additional data showing up when it is not expected.
- UnauthenticatedAdditionalData,
-}
-
-impl fmt::Display for Error {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- match self {
- Self::UnauthenticatedAdditionalData => write!(f, "Unauthenticated aad."),
- }
- }
-}
-
-#[cfg(feature = "std")]
-impl std::error::Error for Error {
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- match self {
- Self::UnauthenticatedAdditionalData => None,
- }
- }
-}
-
/// Encrypt and decrypt content along with an authentication tag.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ChaCha20Poly1305 {
@@ -176,6 +152,35 @@ fn encode_lengths(aad_len: u64, content_len: u64) -> [u8; 16] {
len_buffer
}
+/// Error types for the `ChaCha20Poly1305` AEAD.
+pub mod error {
+ use core::fmt;
+
+ /// Errors encrypting and decrypting messages with `ChaCha20` and `Poly1305` authentication tags.
+ #[derive(Copy, Clone, Debug, PartialEq, Eq)]
+ pub enum Error {
+ /// Additional data showing up when it is not expected.
+ UnauthenticatedAdditionalData,
+ }
+
+ impl fmt::Display for Error {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self {
+ Self::UnauthenticatedAdditionalData => write!(f, "Unauthenticated aad."),
+ }
+ }
+ }
+
+ #[cfg(feature = "std")]
+ impl std::error::Error for Error {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
+ match self {
+ Self::UnauthenticatedAdditionalData => None,
+ }
+ }
+ }
+}
+
#[cfg(test)]
#[cfg(feature = "alloc")]
mod tests {
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.