spiffe_rustls_tokio/error.rs
1//! Error types for `spiffe-rustls-tokio`.
2
3use thiserror::Error;
4
5/// Errors returned by `spiffe-rustls-tokio`.
6#[derive(Debug, Error)]
7#[non_exhaustive]
8pub enum Error {
9 /// A rustls error occurred.
10 ///
11 /// This typically occurs during the TLS handshake, but can also occur
12 /// during connection operations.
13 #[error("rustls error: {0}")]
14 Rustls(#[from] tokio_rustls::rustls::Error),
15
16 /// Failed to parse a peer certificate.
17 ///
18 /// This error occurs when the peer certificate cannot be parsed after a
19 /// successful TLS handshake. Note that missing or multiple SPIFFE IDs do
20 /// not cause this error; they result in `PeerIdentity::spiffe_id` being
21 /// `None`.
22 #[error("failed parsing peer certificate: {0}")]
23 CertParse(String),
24
25 /// The peer certificate does not contain a SPIFFE ID in the URI SAN.
26 ///
27 /// This error is returned by `PeerIdentity::require_spiffe_id()` when
28 /// `spiffe_id` is `None`. This is distinct from `CertParse`, which indicates
29 /// an actual certificate parsing failure.
30 #[error("peer certificate missing SPIFFE ID in URI SAN")]
31 MissingSpiffeId,
32
33 /// An I/O error occurred.
34 #[error("I/O error: {0}")]
35 Io(#[from] std::io::Error),
36}