Skip to content

Commit

Permalink
Implement std::error::Error for pem::Error
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Oct 11, 2024
1 parent 9a1da55 commit 19de199
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/pem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use alloc::format;
use alloc::string::String;
use alloc::vec;
use alloc::vec::Vec;
use core::fmt;
use core::marker::PhantomData;
use core::ops::ControlFlow;
#[cfg(feature = "std")]
Expand Down Expand Up @@ -421,6 +422,26 @@ pub enum Error {
NoItemsFound,
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::MissingSectionEnd { end_marker } => {
write!(f, "missing section end marker: {end_marker:?}")
}
Self::IllegalSectionStart { line } => {
write!(f, "illegal section start: {line:?}")
}
Self::Base64Decode(e) => write!(f, "base64 decode error: {e}"),
#[cfg(feature = "std")]
Self::Io(e) => write!(f, "{e}"),
Self::NoItemsFound => write!(f, "no items found"),
}
}
}

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

// Ported from https://github.com/rust-lang/rust/blob/91cfcb021935853caa06698b759c293c09d1e96a/library/std/src/io/mod.rs#L1990 and
// modified to look for our accepted newlines.
#[cfg(feature = "std")]
Expand Down

0 comments on commit 19de199

Please sign in to comment.