5
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
6
*/
7
7
8
+ //! rustls-mbedpki-provider
9
+ //!
10
+ //! rustls-mbedpki-provider is a pki provider for rustls based on [mbedtls].
11
+ //!
12
+ //! [mbedtls]: https://github.com/fortanix/rust-mbedtls
13
+
14
+ // Require docs for public APIs, deny unsafe code, etc.
15
+ #![ forbid( unsafe_code, unused_must_use) ]
16
+ #![ cfg_attr( not( bench) , forbid( unstable_features) ) ]
17
+ #![ deny(
18
+ clippy:: alloc_instead_of_core,
19
+ clippy:: clone_on_ref_ptr,
20
+ clippy:: std_instead_of_core,
21
+ clippy:: use_self,
22
+ clippy:: upper_case_acronyms,
23
+ trivial_casts,
24
+ trivial_numeric_casts,
25
+ missing_docs,
26
+ unreachable_pub,
27
+ unused_import_braces,
28
+ unused_extern_crates,
29
+ unused_qualifications
30
+ ) ]
31
+
32
+ // Enable documentation for all features on docs.rs
33
+ #![ cfg_attr( docsrs, feature( doc_cfg, doc_auto_cfg) ) ]
34
+ #![ cfg_attr( bench, feature( test) ) ]
35
+
8
36
use chrono:: NaiveDateTime ;
9
37
use mbedtls:: hash:: Type ;
10
38
use pki_types:: CertificateDer ;
@@ -14,27 +42,24 @@ use std::sync::Arc;
14
42
#[ cfg( test) ]
15
43
mod tests_common;
16
44
45
+ /// module for implementation of [ClientCertVerifier]
17
46
pub mod client_cert_verifier;
47
+ /// module for implementation of [ServerCertVerifier]
18
48
pub mod server_cert_verifier;
19
49
20
50
pub use client_cert_verifier:: MbedTlsClientCertVerifier ;
21
51
pub use server_cert_verifier:: MbedTlsServerCertVerifier ;
22
52
23
53
/// A config about whether to check certificate validity period
24
- #[ derive( Debug , PartialEq , Eq , Clone ) ]
54
+ #[ derive( Debug , PartialEq , Eq , Clone , Default ) ]
25
55
pub struct CertActiveCheck {
26
- /// If accept expired certificate, default to false
56
+ /// Accept expired certificates
27
57
pub ignore_expired : bool ,
28
- /// If accept not active certificate, default to false
58
+ /// Accept certificates that are not yet active
29
59
pub ignore_not_active_yet : bool ,
30
60
}
31
61
32
- impl Default for CertActiveCheck {
33
- fn default ( ) -> Self {
34
- Self { ignore_expired : false , ignore_not_active_yet : false }
35
- }
36
- }
37
-
62
+ /// Helper function to convert a [`CertificateDer`] to [`mbedtls::x509::Certificate`]
38
63
pub fn rustls_cert_to_mbedtls_cert ( cert : & CertificateDer ) -> mbedtls:: Result < mbedtls:: alloc:: Box < mbedtls:: x509:: Certificate > > {
39
64
let cert = mbedtls:: x509:: Certificate :: from_der ( cert) ?;
40
65
Ok ( cert)
@@ -45,6 +70,7 @@ pub fn mbedtls_err_into_rustls_err(err: mbedtls::Error) -> rustls::Error {
45
70
mbedtls_err_into_rustls_err_with_error_msg ( err, "" )
46
71
}
47
72
73
+ /// All supported signature schemas
48
74
pub const SUPPORTED_SIGNATURE_SCHEMA : [ SignatureScheme ; 9 ] = [
49
75
rustls:: SignatureScheme :: RSA_PSS_SHA512 ,
50
76
rustls:: SignatureScheme :: RSA_PSS_SHA384 ,
@@ -90,7 +116,8 @@ pub fn mbedtls_err_into_rustls_err_with_error_msg(err: mbedtls::Error, msg: &str
90
116
}
91
117
}
92
118
93
- pub fn rustls_signature_scheme_to_mbedtls_hash_type ( signature_scheme : SignatureScheme ) -> mbedtls:: hash:: Type {
119
+ /// Helper function to convert rustls [`SignatureScheme`] to mbedtls [`Type`]
120
+ pub fn rustls_signature_scheme_to_mbedtls_hash_type ( signature_scheme : SignatureScheme ) -> Type {
94
121
match signature_scheme {
95
122
SignatureScheme :: RSA_PKCS1_SHA1 => Type :: Sha1 ,
96
123
SignatureScheme :: ECDSA_SHA1_Legacy => Type :: Sha1 ,
@@ -110,6 +137,7 @@ pub fn rustls_signature_scheme_to_mbedtls_hash_type(signature_scheme: SignatureS
110
137
}
111
138
}
112
139
140
+ /// Helper function to convert rustls [`SignatureScheme`] to mbedtls [`mbedtls::pk::Options`]
113
141
pub fn rustls_signature_scheme_to_mbedtls_pk_options ( signature_scheme : SignatureScheme ) -> Option < mbedtls:: pk:: Options > {
114
142
use mbedtls:: pk:: Options ;
115
143
use mbedtls:: pk:: RsaPadding ;
@@ -133,7 +161,8 @@ pub fn rustls_signature_scheme_to_mbedtls_pk_options(signature_scheme: Signature
133
161
}
134
162
}
135
163
136
- fn rustls_signature_scheme_to_mbedtls_curve_id ( signature_scheme : SignatureScheme ) -> mbedtls:: pk:: EcGroupId {
164
+ /// Helper function to convert rustls [`SignatureScheme`] to mbedtls [`mbedtls::pk::EcGroupId`]
165
+ pub fn rustls_signature_scheme_to_mbedtls_curve_id ( signature_scheme : SignatureScheme ) -> mbedtls:: pk:: EcGroupId {
137
166
// reference: https://www.rfc-editor.org/rfc/rfc8446.html#section-4.2.3
138
167
use mbedtls:: pk:: EcGroupId ;
139
168
match signature_scheme {
@@ -156,7 +185,7 @@ fn rustls_signature_scheme_to_mbedtls_curve_id(signature_scheme: SignatureScheme
156
185
}
157
186
158
187
/// Returns the size of the message digest given the hash type.
159
- fn hash_size_bytes ( hash_type : mbedtls :: hash :: Type ) -> Option < usize > {
188
+ fn hash_size_bytes ( hash_type : Type ) -> Option < usize > {
160
189
match hash_type {
161
190
mbedtls:: hash:: Type :: None => None ,
162
191
mbedtls:: hash:: Type :: Md2 => Some ( 16 ) ,
@@ -171,7 +200,8 @@ fn hash_size_bytes(hash_type: mbedtls::hash::Type) -> Option<usize> {
171
200
}
172
201
}
173
202
174
- pub fn buffer_for_hash_type ( hash_type : mbedtls:: hash:: Type ) -> Option < Vec < u8 > > {
203
+ /// Returns the a ready to use empty [`Vec<u8>`] for the message digest with given hash type.
204
+ pub fn buffer_for_hash_type ( hash_type : Type ) -> Option < Vec < u8 > > {
175
205
let size = hash_size_bytes ( hash_type) ?;
176
206
Some ( vec ! [ 0 ; size] )
177
207
}
0 commit comments