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 #26

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 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
3 changes: 2 additions & 1 deletion 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 All @@ -31,7 +32,7 @@ default = ["std"]

# Enables all features, including support of simplified Cocoon API, using `rand::thread_rng`,
# and API related to `std::io`: wrap to writer, unwrap from reader.
std = ["alloc", "rand/std"]
std = ["alloc", "rand/std", "thiserror"]
Copy link
Owner

@fadeevab fadeevab May 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@madonuko Let's make it optional, you will enable it in your code.

Suggested change
std = ["alloc", "rand/std", "thiserror"]
std = ["alloc", "rand/std"]

Then I can quickly merge it, I will improve the documentation and I will release it shortly.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@madonuko Broke your PR... See the fix: #28

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty much perfect to me


# Enables `Vec` container. Can be used without `std` crate (in "no std" build).
alloc = ["chacha20poly1305/alloc"]
Expand Down
6 changes: 6 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
/// Error variants produced by the Cocoon API.
#[derive(Debug)]
#[cfg_attr(feature = "std", derive(thiserror::Error))]
pub enum Error {
/// I/o error during read/write operation (`Cocoon::dump`, `Cocoon::parse`).
#[cfg(feature = "std")]
#[error("Input/output error")]
Io(std::io::Error),
/// Format is not recognized. Probably corrupted.
#[cfg_attr(feature = "std", error("Unrecognized format"))]
UnrecognizedFormat,
/// Cryptographic error. There could be a few reasons:
/// 1. Integrity is compromised.
/// 2. Password is invalid.
#[cfg_attr(feature = "std", 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 = "std", 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 = "std", error("Insufficient buffer size for decrypted data"))]
TooShort,
}

Expand Down
Loading