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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use std::{fmt, io, string};
#[derive(Debug)]
pub enum Error {
Io(io::Error),
Decode(base64::DecodeError),
Utf8Error(string::FromUtf8Error),
InvalidCertType(u32),
InvalidFormat,
UnexpectedEof,
NotCertificate,
KeyTypeMismatch,
CertificateInvalidSignature,
SigningError,
EncryptedPrivateKeyNotSupported,
UnknownKeyType(String),
UnknownCurve(String),
#[cfg(feature = "yubikey")]
YubikeyError(crate::yubikey::Error),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Io(ref err) => err.fmt(f),
Error::Decode(ref err) => err.fmt(f),
Error::Utf8Error(ref err) => err.fmt(f),
Error::InvalidFormat => write!(f, "Invalid format"),
Error::InvalidCertType(v) => write!(f, "Invalid certificate type with value {}", v),
Error::UnexpectedEof => write!(f, "Unexpected EOF reached while reading data"),
Error::NotCertificate => write!(f, "Not a certificate"),
Error::KeyTypeMismatch => write!(f, "Key type mismatch"),
Error::CertificateInvalidSignature => write!(f, "Certificate is improperly signed"),
Error::SigningError => write!(f, "Could not sign data"),
Error::EncryptedPrivateKeyNotSupported => write!(f, "Encrypted private keys are not supported"),
Error::UnknownKeyType(ref v) => write!(f, "Unknown key type {}", v),
Error::UnknownCurve(ref v) => write!(f, "Unknown curve {}", v),
#[cfg(feature = "yubikey")]
Error::YubikeyError(ref e) => write!(f, "{}", e),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Io(ref e) => e.source(),
Error::Decode(ref e) => e.source(),
Error::Utf8Error(ref e) => e.source(),
_ => None,
}
}
}
impl From<io::Error> for Error {
fn from(error: io::Error) -> Self {
Error::Io(error)
}
}
impl From<base64::DecodeError> for Error {
fn from(error: base64::DecodeError) -> Error {
Error::Decode(error)
}
}
impl From<string::FromUtf8Error> for Error {
fn from(error: string::FromUtf8Error) -> Error {
Error::Utf8Error(error)
}
}
impl From<ring::error::Unspecified> for Error {
fn from(_: ring::error::Unspecified) -> Error{
Error::CertificateInvalidSignature
}
}
#[cfg(feature = "rsa-signing")]
impl From<simple_asn1::ASN1EncodeErr> for Error {
fn from(_e: simple_asn1::ASN1EncodeErr) -> Self {
Error::InvalidFormat
}
}