Skip to content

Commit

Permalink
add std error
Browse files Browse the repository at this point in the history
  • Loading branch information
bhesh committed Nov 20, 2023
1 parent 9e8e854 commit 0dc31be
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ ed25519 = [ "sha2", "dep:ed25519-dalek" ]
x509 = [ "dep:x509-cert", "dep:ocsp-x509" ]
pem = [ "x509", "der/pem", "x509-cert?/pem" ]
strict = []
std = []

[package.metadata.docs.rs]
all-features = true
Expand Down
17 changes: 17 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Verification Errors

use alloc::fmt;
use core::convert::Infallible;
use der::asn1::ObjectIdentifier;

Expand All @@ -25,6 +26,22 @@ pub enum Error {
Encode,
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Verification => write!(f, "Verification failure"),
Error::InvalidKey => write!(f, "Invalid key"),
Error::InvalidSignature => write!(f, "Invalid signature"),
Error::UnknownOid(oid) => write!(f, "Unknown OID: {}", oid),
Error::Decode => write!(f, "Decode failure"),
Error::Encode => write!(f, "Encode failure"),
}
}
}

#[cfg(feature = "std")]
impl std::error::Error for Error {}

impl From<Infallible> for Error {
fn from(_: Infallible) -> Self {
unreachable!()
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

extern crate alloc;

#[cfg(feature = "std")]
extern crate std;

mod error;
pub use error::Error;

Expand Down

0 comments on commit 0dc31be

Please sign in to comment.