Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement std::error::Error for cocoon::Error via optional thiserror #28

Merged
merged 8 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ hmac = "0.11"
pbkdf2 = {version = "0.9", default-features = false, features = ["sha2", "hmac"]}
rand = {version = "0.8", default-features = false, features = ["std_rng"]}
sha2 = {version = "0.9", default-features = false}
thiserror = {version = "1.0.61", optional = true}
zeroize = {version = "1", default-features = false}

[dev-dependencies]
Expand Down
19 changes: 19 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
/// Error variants produced by the Cocoon API.
#[derive(Debug)]
#[cfg_attr(feature = "thiserror", derive(thiserror::Error))]
pub enum Error {
/// I/o error during read/write operation (`Cocoon::dump`, `Cocoon::parse`).
#[cfg(feature = "std")]
#[cfg_attr(feature = "thiserror", error("Input/output error"))]
Io(std::io::Error),

/// Format is not recognized. Probably corrupted.
#[cfg_attr(feature = "thiserror", error("Unrecognized format"))]
UnrecognizedFormat,

/// Cryptographic error. There could be a few reasons:
/// 1. Integrity is compromised.
/// 2. Password is invalid.
#[cfg_attr(
feature = "thiserror",
error("Cryptographic error: bad integrity/password")
)]
Cryptography,

/// Container is too large to get processed on the current architecture.
/// E.g. it's not possible to process a container larger than 4 GB on 32-bit architecture.
#[cfg_attr(
feature = "thiserror",
error("Container size exceeds architectural limit")
)]
TooLarge,

/// Buffer is too short and barely holds all data to decrypt, inconsistent length
/// encoded to the header.
#[cfg_attr(
feature = "thiserror",
error("Insufficient buffer size for decrypted data")
)]
TooShort,
}

Expand Down
Loading