1use core::{
2 error::Error,
3 fmt::{self, Display},
4 num::TryFromIntError,
5};
6
7#[derive(Debug, Eq, PartialEq)]
9pub enum QuoteParseError {
10 Parse,
11 Verification,
12 UnknownCertificationDataType,
13 UnknownQuoteVersion,
14 IntConversionError,
15 UnsupportedAttestationKeyType,
16 AttestationKeyDoesNotMatch,
17}
18
19impl Display for QuoteParseError {
20 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21 match self {
22 QuoteParseError::Parse => f.write_str("Cannot parse quote"),
23 QuoteParseError::Verification => f.write_str("Signature is invalid"),
24 QuoteParseError::UnknownCertificationDataType => {
25 f.write_str("Unknown certification data type")
26 }
27 QuoteParseError::UnknownQuoteVersion => f.write_str("Unknown quote version"),
28 QuoteParseError::IntConversionError => f.write_str("Integer conversion error"),
29 QuoteParseError::UnsupportedAttestationKeyType => {
30 f.write_str("Unsupported attestion key type")
31 }
32 QuoteParseError::AttestationKeyDoesNotMatch => {
33 f.write_str("Attestation key does not match hash in QE report")
34 }
35 }
36 }
37}
38
39impl From<nom::Err<nom::error::Error<&[u8]>>> for QuoteParseError {
40 fn from(_: nom::Err<nom::error::Error<&[u8]>>) -> QuoteParseError {
41 QuoteParseError::Parse
42 }
43}
44
45impl From<p256::ecdsa::Error> for QuoteParseError {
46 fn from(_: p256::ecdsa::Error) -> QuoteParseError {
47 QuoteParseError::Verification
48 }
49}
50
51impl From<TryFromIntError> for QuoteParseError {
52 fn from(_: TryFromIntError) -> QuoteParseError {
53 QuoteParseError::IntConversionError
54 }
55}
56
57impl Error for QuoteParseError {}
58
59#[derive(Debug, Eq, PartialEq)]
61pub enum QuoteVerificationError {
62 NoQeReportCertificationData,
63 BadSignature,
64 NoPckCertChain,
65 #[cfg(feature = "pck")]
66 PckParseVerify(crate::pck::PckParseVerifyError),
67}
68
69impl Display for QuoteVerificationError {
70 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
71 match self {
72 QuoteVerificationError::NoQeReportCertificationData => {
73 f.write_str("Quote has no QE report certification data")
74 }
75 QuoteVerificationError::BadSignature => {
76 f.write_str("Quote signature verification failed")
77 }
78 QuoteVerificationError::NoPckCertChain => {
79 f.write_str("Quote has no PCK certificate chain")
80 }
81 #[cfg(feature = "pck")]
82 QuoteVerificationError::PckParseVerify(error) => {
83 write!(f, "PCK certificate: {error}")
84 }
85 }
86 }
87}
88
89impl From<p256::ecdsa::Error> for QuoteVerificationError {
90 fn from(_: p256::ecdsa::Error) -> QuoteVerificationError {
91 QuoteVerificationError::BadSignature
92 }
93}
94
95#[cfg(feature = "pck")]
96impl From<crate::pck::PckParseVerifyError> for QuoteVerificationError {
97 fn from(error: crate::pck::PckParseVerifyError) -> QuoteVerificationError {
98 QuoteVerificationError::PckParseVerify(error)
99 }
100}
101
102impl Error for QuoteVerificationError {}
103
104#[derive(Debug, Eq, PartialEq)]
106pub enum VerifyingKeyError {
107 DecodeEncodedPoint,
108 EncodedPointToVerifyingKey,
109 BadSize,
110}
111
112impl Display for VerifyingKeyError {
113 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
114 match self {
115 VerifyingKeyError::DecodeEncodedPoint => {
116 f.write_str("Could not decode to encoded point")
117 }
118 VerifyingKeyError::EncodedPointToVerifyingKey => {
119 f.write_str("Could not convert encoded point to verifying key")
120 }
121 VerifyingKeyError::BadSize => f.write_str("Compressed point has unexpected size"),
122 }
123 }
124}
125
126impl Error for VerifyingKeyError {
127 fn source(&self) -> Option<&(dyn Error + 'static)> {
128 None
129 }
130}