1#![cfg_attr(not(any(test, feature = "std")), no_std)]
2#![doc = include_str!("../README.md")]
3#![warn(clippy::pedantic)]
4#![allow(
5 clippy::module_name_repetitions,
6 clippy::cast_possible_truncation,
7 clippy::cast_sign_loss,
8 clippy::missing_errors_doc )]
10#![cfg_attr(docsrs, feature(doc_cfg))]
11
12pub(crate) mod fmt;
53
54use parse_buffer::ParseError;
55pub mod alert;
56mod application_data;
57pub mod blocking;
58mod buffer;
59mod change_cipher_spec;
60mod cipher_suites;
61mod common;
62mod config;
63mod connection;
64mod content_types;
65mod crypto_engine;
66mod extensions;
67pub mod flush_policy;
68mod handshake;
69mod key_schedule;
70mod parse_buffer;
71pub mod read_buffer;
72mod record;
73mod record_reader;
74mod write_buffer;
75
76pub use config::UnsecureProvider;
77pub use extensions::extension_data::signature_algorithms::SignatureScheme;
78pub use handshake::certificate_verify::CertificateVerify;
79pub use rand_core::{CryptoRng, CryptoRngCore};
80
81#[cfg(feature = "webpki")]
82pub mod webpki;
83
84#[cfg(feature = "rustpki")]
85mod der_certificate;
86#[cfg(feature = "rustpki")]
87pub mod pki;
88
89mod asynch;
90pub use asynch::*;
91
92pub use flush_policy::*;
93
94#[derive(Debug, Copy, Clone)]
95#[cfg_attr(feature = "defmt", derive(defmt::Format))]
96pub enum TlsError {
97 ConnectionClosed,
98 Unimplemented,
99 MissingHandshake,
100 HandshakeAborted(alert::AlertLevel, alert::AlertDescription),
101 AbortHandshake(alert::AlertLevel, alert::AlertDescription),
102 IoError,
103 InternalError,
104 InvalidRecord,
105 UnknownContentType,
106 InvalidNonceLength,
107 InvalidTicketLength,
108 UnknownExtensionType,
109 InsufficientSpace,
110 InvalidHandshake,
111 InvalidCipherSuite,
112 InvalidSignatureScheme,
113 InvalidSignature,
114 InvalidExtensionsLength,
115 InvalidSessionIdLength,
116 InvalidSupportedVersions,
117 InvalidApplicationData,
118 InvalidKeyShare,
119 InvalidCertificate,
120 InvalidCertificateEntry,
121 InvalidCertificateRequest,
122 InvalidPrivateKey,
123 UnableToInitializeCryptoEngine,
124 ParseError(ParseError),
125 OutOfMemory,
126 CryptoError,
127 EncodeError,
128 DecodeError,
129 Io(embedded_io::ErrorKind),
130}
131
132impl embedded_io::Error for TlsError {
133 fn kind(&self) -> embedded_io::ErrorKind {
134 if let Self::Io(k) = self {
135 *k
136 } else {
137 error!("TLS error: {:?}", self);
138 embedded_io::ErrorKind::Other
139 }
140 }
141}
142
143impl core::fmt::Display for TlsError {
144 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
145 write!(f, "{self:?}")
146 }
147}
148
149impl core::error::Error for TlsError {}
150
151#[cfg(feature = "std")]
152mod stdlib {
153 use crate::config::TlsClock;
154
155 use std::time::SystemTime;
156 impl TlsClock for SystemTime {
157 fn now() -> Option<u64> {
158 Some(
159 SystemTime::now()
160 .duration_since(SystemTime::UNIX_EPOCH)
161 .unwrap()
162 .as_secs(),
163 )
164 }
165 }
166}
167
168fn unused<T>(_: T) {}