1pub use rustls::CertificateError;
2use thiserror::Error;
3
4use crate::{Epoch, SignatureScheme};
5
6#[derive(Clone, Copy, Debug, Eq, PartialEq)]
7pub struct TlsAlert {
8 description: u8,
9}
10
11impl TlsAlert {
12 pub fn description(self) -> u8 {
13 self.description
14 }
15
16 pub(crate) fn new(description: rustls::AlertDescription) -> Self {
17 Self { description: description.into() }
18 }
19}
20
21#[derive(Debug, Error)]
22pub enum TlsConfigError {
23 #[error("root certificates have not been configured")]
24 RootCertsNotSet,
25 #[error("TLS configuration is invalid: {0}")]
26 Invalid(String),
27 #[error("the selected crypto provider has no QUIC-capable TLS 1.3 cipher suite")]
28 MissingQuicSuite,
29 #[error("FIPS mode requires a FIPS crypto provider and TLS configuration")]
30 FipsRequired,
31}
32
33#[derive(Debug, Error)]
34pub enum InvalidLocalAuthority {
35 #[error("authority name is not a valid DNS name")]
36 InvalidName,
37 #[error("authority certificate chain is empty")]
38 EmptyCertificateChain,
39 #[error("authority OCSP staple is empty")]
40 EmptyOcsp,
41 #[error("authority leaf certificate is invalid: {0}")]
42 InvalidCertificate(String),
43 #[error("authority private key is invalid or does not match its certificate: {0}")]
44 InvalidPrivateKey(String),
45}
46
47#[derive(Debug, Error)]
48pub enum CryptoError {
49 #[error("invalid authentication tag buffer length: expected {expected}, got {actual}")]
50 InvalidTagLength { expected: usize, actual: usize },
51 #[error("QUIC key operation failed")]
52 OperationFailed,
53}
54
55#[derive(Debug, Error)]
56pub enum PeerTlsError {
57 #[error("received CRYPTO data at {actual:?}; expected {expected:?}")]
58 WrongCryptoLevel { expected: Epoch, actual: Epoch },
59 #[error("TLS peer exceeded {resource} limit of {limit} bytes")]
60 ResourceLimit { resource: &'static str, limit: usize },
61 #[error("TLS peer error: {0}")]
62 Protocol(String),
63}
64
65#[derive(Debug, Error)]
66pub enum TlsInvariantError {
67 #[error("TLS backend did not provide {0}")]
68 Missing(&'static str),
69 #[error("TLS backend produced an event after reaching a terminal state")]
70 EventAfterTerminal,
71}
72
73#[derive(Debug, Error)]
74pub enum TlsError {
75 #[error(transparent)]
76 Config(#[from] TlsConfigError),
77 #[error("TLS alert {0:?}")]
78 Alert(TlsAlert),
79 #[error(transparent)]
80 Peer(#[from] PeerTlsError),
81 #[error(transparent)]
82 Invariant(#[from] TlsInvariantError),
83 #[error(transparent)]
84 Crypto(#[from] CryptoError),
85}
86
87#[derive(Debug, Error)]
88#[error("TLS handshake is not complete")]
89pub struct HandshakeNotComplete;
90
91#[derive(Debug, Error)]
92pub enum ExporterError {
93 #[error("TLS exporter failed")]
94 Failed,
95}
96
97#[derive(Debug, Error)]
98pub enum StoreError {
99 #[error("resumption store failed: {0}")]
100 Backend(String),
101}
102
103#[derive(Debug, Error)]
104pub enum SignError {
105 #[error("signature scheme {scheme:?} is not supported by this authority")]
106 UnsupportedScheme { scheme: SignatureScheme },
107 #[error("signing failed")]
108 SigningFailed,
109}