pub mod client;
pub mod credentials;
pub mod fingerprint;
pub mod identity;
pub mod pem;
pub mod server;
pub mod signing;
pub use fingerprint::{extract_ed25519_raw_key_from_spki, fingerprint_from_cert_der};
pub use pem::{load_cert_chain, load_private_key};
pub use signing::Ed25519SigningKey;
pub use identity::{AcmeDirectory, Ed25519SecretKey, TlsIdentity};
pub use client::{
build_client_auth, load_platform_root_cert_store, select_server_verifier,
FingerprintPinVerifier, NoClientCertResolver, RawKeyClientCertResolver, TlsClientConfig,
};
pub use credentials::{ConnectionCredentials, RemoteIdentity};
pub use server::{
build_rustls_server_config, generate_self_signed_cert, AcceptAnyCertVerifier,
RawKeyCertResolver, SelfSignedCert, TlsServerConfig, VerifyPresentedCertVerifier,
};
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum TlsError {
#[error("loading cert/key material: {0}")]
CertLoad(#[from] std::io::Error),
#[error("generating self-signed cert: {0}")]
SelfSigned(#[from] rcgen::Error),
#[error("building rustls config: {0}")]
Rustls(#[from] rustls::Error),
#[error("building webpki verifier: {0}")]
VerifierBuild(#[from] rustls::client::VerifierBuilderError),
#[cfg(feature = "noq")]
#[error("wrapping rustls config for noq: {0}")]
NoqWrap(#[from] noq_proto::crypto::rustls::NoInitialCipherSuite),
#[error("TLS config error: {0}")]
AcmeConfig(String),
}
#[cfg(test)]
mod tests {
use super::TlsError;
#[test]
fn tls_error_matches_the_adr_002_variant_set() {
let io: TlsError = std::io::Error::other("x").into();
assert!(matches!(io, TlsError::CertLoad(_)));
let rcgen: TlsError = rcgen::Error::CouldNotParseCertificate.into();
assert!(matches!(rcgen, TlsError::SelfSigned(_)));
let rustls: TlsError = rustls::Error::General("x".into()).into();
assert!(matches!(rustls, TlsError::Rustls(_)));
let builder: TlsError = rustls::client::VerifierBuilderError::NoRootAnchors.into();
assert!(matches!(builder, TlsError::VerifierBuild(_)));
let acme = TlsError::AcmeConfig("acme feature not enabled".into());
assert!(acme.to_string().contains("acme feature not enabled"));
}
#[cfg(feature = "noq")]
#[test]
fn tls_error_noq_wrap_variant_exists() {
let _ = matches!(
Option::<TlsError>::None,
Some(TlsError::NoqWrap(_)) | Some(_)
);
}
}