diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-03-05 14:19:32 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-03-09 11:52:38 +0100 |
commit | 247c0afa9af65d5ba357f77feac2229b3db5983e (patch) | |
tree | 7f560c0812d78dd3abe78de2107de946588dab90 | |
parent | b6a8166235f6ea76e2c7e286431d892f0a28e57d (diff) |
openpgp: Define openpgp::Error using thiserror.
-rw-r--r-- | Cargo.lock | 21 | ||||
-rw-r--r-- | openpgp/Cargo.toml | 1 | ||||
-rw-r--r-- | openpgp/src/lib.rs | 58 |
3 files changed, 51 insertions, 29 deletions
@@ -1664,6 +1664,7 @@ dependencies = [ "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "rpassword 4.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "thiserror 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-normalization 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1897,6 +1898,24 @@ dependencies = [ ] [[package]] +name = "thiserror" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "thiserror-impl 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "thread_local" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2434,6 +2453,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" "checksum term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "edd106a334b7657c10b7c540a0106114feadeb4dc314513e97df481d5d966f42" "checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +"checksum thiserror 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "ee14bf8e6767ab4c687c9e8bc003879e042a96fd67a3ba5934eadb6536bef4db" +"checksum thiserror-impl 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "a7b51e1fbc44b5a0840be594fbc0f960be09050f2617e61e6aa43bef97cd3ef4" "checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" "checksum tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "5a09c0b5bb588872ab2f09afa13ee6e9dac11e10a0ec9e8e3ba39a5a5d530af6" diff --git a/openpgp/Cargo.toml b/openpgp/Cargo.toml index da36da75..1e50e376 100644 --- a/openpgp/Cargo.toml +++ b/openpgp/Cargo.toml @@ -35,6 +35,7 @@ nettle = "6.0.1" quickcheck = { version = "0.9", default-features = false } rand = { version = "0.7", default-features = false } regex = "1" +thiserror = "1" unicode-normalization = "< 0.1.10" [build-dependencies] diff --git a/openpgp/src/lib.rs b/openpgp/src/lib.rs index 96d23f49..792d91db 100644 --- a/openpgp/src/lib.rs +++ b/openpgp/src/lib.rs @@ -188,91 +188,91 @@ fn frozen_time() -> std::time::SystemTime { /// Crate result specialization. pub type Result<T> = ::std::result::Result<T, failure::Error>; -#[derive(Fail, Debug, Clone)] +#[derive(thiserror::Error, Debug, Clone)] /// Errors returned by this module. /// /// Note: This enum cannot be exhaustively matched to allow future /// extensions. pub enum Error { /// Invalid argument. - #[fail(display = "Invalid argument: {}", _0)] + #[error("Invalid argument: {0}")] InvalidArgument(String), /// Invalid operation. - #[fail(display = "Invalid operation: {}", _0)] + #[error("Invalid operation: {0}")] InvalidOperation(String), /// A malformed packet. - #[fail(display = "Malformed packet: {}", _0)] + #[error("Malformed packet: {0}")] MalformedPacket(String), /// Packet size exceeds the configured limit. - #[fail(display = "{} Packet ({} bytes) exceeds limit of {} bytes", + #[error("{} Packet ({} bytes) exceeds limit of {} bytes", _0, _1, _2)] PacketTooLarge(packet::Tag, u32, u32), /// Unsupported packet type. - #[fail(display = "Unsupported packet type. Tag: {}", _0)] + #[error("Unsupported packet type. Tag: {0}")] UnsupportedPacketType(packet::Tag), /// Unsupported hash algorithm identifier. - #[fail(display = "Unsupported hash algorithm: {}", _0)] + #[error("Unsupported hash algorithm: {0}")] UnsupportedHashAlgorithm(HashAlgorithm), /// Unsupported public key algorithm identifier. - #[fail(display = "Unsupported public key algorithm: {}", _0)] + #[error("Unsupported public key algorithm: {0}")] UnsupportedPublicKeyAlgorithm(PublicKeyAlgorithm), /// Unsupported elliptic curve ASN.1 OID. - #[fail(display = "Unsupported elliptic curve: {}", _0)] + #[error("Unsupported elliptic curve: {0}")] UnsupportedEllipticCurve(types::Curve), /// Unsupported symmetric key algorithm. - #[fail(display = "Unsupported symmetric algorithm: {}", _0)] + #[error("Unsupported symmetric algorithm: {0}")] UnsupportedSymmetricAlgorithm(SymmetricAlgorithm), /// Unsupported AEAD algorithm. - #[fail(display = "Unsupported AEAD algorithm: {}", _0)] + #[error("Unsupported AEAD algorithm: {0}")] UnsupportedAEADAlgorithm(types::AEADAlgorithm), /// Unsupported Compression algorithm. - #[fail(display = "Unsupported Compression algorithm: {}", _0)] + #[error("Unsupported Compression algorithm: {0}")] UnsupportedCompressionAlgorithm(types::CompressionAlgorithm), /// Unsupported signature type. - #[fail(display = "Unsupported signature type: {}", _0)] + #[error("Unsupported signature type: {0}")] UnsupportedSignatureType(SignatureType), /// Invalid password. - #[fail(display = "Invalid password")] + #[error("Invalid password")] InvalidPassword, /// Invalid session key. - #[fail(display = "Invalid session key: {}", _0)] + #[error("Invalid session key: {0}")] InvalidSessionKey(String), /// Missing session key. - #[fail(display = "Missing session key: {}", _0)] + #[error("Missing session key: {0}")] MissingSessionKey(String), /// Malformed MPI. - #[fail(display = "Malformed MPI: {}", _0)] + #[error("Malformed MPI: {0}")] MalformedMPI(String), /// Bad signature. - #[fail(display = "Bad signature: {}", _0)] + #[error("Bad signature: {0}")] BadSignature(String), /// Message has been manipulated. - #[fail(display = "Message has been manipulated")] + #[error("Message has been manipulated")] ManipulatedMessage, /// Malformed message. - #[fail(display = "Malformed Message: {}", _0)] + #[error("Malformed Message: {0}")] MalformedMessage(String), /// Malformed certificate. - #[fail(display = "Malformed Cert: {}", _0)] + #[error("Malformed Cert: {0}")] MalformedCert(String), /// Unsupported Cert. @@ -280,39 +280,39 @@ pub enum Error { /// This usually occurs, because the primary key is in an /// unsupported format. In particular, Sequoia does not support /// version 3 keys. - #[fail(display = "Unsupported Cert: {}", _0)] + #[error("Unsupported Cert: {0}")] UnsupportedCert(String), /// Index out of range. - #[fail(display = "Index out of range")] + #[error("Index out of range")] IndexOutOfRange, /// Expired. - #[fail(display = "Expired on {:?}", _0)] + #[error("Expired on {0:?}")] Expired(std::time::SystemTime), /// Not yet live. - #[fail(display = "Not live until {:?}", _0)] + #[error("Not live until {0:?}")] NotYetLive(std::time::SystemTime), /// No binding signature. - #[fail(display = "No binding signature at time {:?}", _0)] + #[error("No binding signature at time {0:?}")] NoBindingSignature(std::time::SystemTime), /// Invalid key. - #[fail(display = "Invalid key: {:?}", _0)] + #[error("Invalid key: {0:?}")] InvalidKey(String), /// The operation is not allowed, because it violates the policy. /// /// The optional time is the time at which the operation was /// determined to no longer be secure. - #[fail(display = "Not secure as of: {:?}: {}", _1, _0)] + #[error("Not secure as of: {1:?}: {0}")] PolicyViolation(String, Option<std::time::SystemTime>), /// This marks this enum as non-exhaustive. Do not use this /// variant. - #[doc(hidden)] #[fail(display = "__Nonexhaustive")] __Nonexhaustive, + #[doc(hidden)] #[error("__Nonexhaustive")] __Nonexhaustive, } /// The OpenPGP packets that Sequoia understands. |