1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#![doc = include_str!("../README.md")]
#![allow(clippy::or_fun_call)]
#[macro_use]
pub extern crate asn1_der;
mod de;
mod misc;
mod ser;
#[cfg(feature = "any")]
mod any;
pub use crate::{
de::{from_bytes, from_reader, from_source},
ser::{to_sink, to_vec, to_writer},
};
#[cfg(feature = "any")]
pub use crate::any::AnyObject;
pub use asn1_der::VecBacking;
pub use serde;
use asn1_der::Asn1DerError;
use std::{
error::Error,
fmt::{self, Display, Formatter},
};
#[derive(Debug)]
pub enum SerdeAsn1DerError {
Asn1DerError(Asn1DerError),
SerdeError(String),
}
impl Display for SerdeAsn1DerError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
SerdeAsn1DerError::Asn1DerError(e) => e.fmt(f),
SerdeAsn1DerError::SerdeError(s) => write!(f, "Serde error: {}", s),
}
}
}
impl Error for SerdeAsn1DerError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
SerdeAsn1DerError::Asn1DerError(e) => e.source(),
_ => None,
}
}
}
impl serde::de::Error for SerdeAsn1DerError {
fn custom<T>(msg: T) -> Self
where
T: Display,
{
SerdeAsn1DerError::SerdeError(msg.to_string())
}
}
impl serde::ser::Error for SerdeAsn1DerError {
fn custom<T>(msg: T) -> Self
where
T: Display,
{
SerdeAsn1DerError::SerdeError(msg.to_string())
}
}
impl From<Asn1DerError> for SerdeAsn1DerError {
fn from(e: Asn1DerError) -> Self {
SerdeAsn1DerError::Asn1DerError(e)
}
}
pub type Result<T> = std::result::Result<T, SerdeAsn1DerError>;