1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#[derive(Debug, Clone)]
/// Supported encodings for client certificates.
pub enum ContentEncoding {
/// PEM encoding.
PEM,
/// DER encoding.
DER,
}
/// Identity
pub trait Identity {
/// Load DER encoded certificate and key from a slice of bytes
///
/// # Arguments
///
/// * `cert` - The DER encoded certificate.
/// * `key` - The DER encoded PKCS8 private key.
/// * `encoding` - The encoding of the certificate and key.
///
/// # Returns
///
/// * `Identity` - The new Identity instance.
fn from_pkcs8(cert: &[u8], key: &[u8], encoding: ContentEncoding) -> Self;
/// Load DER encoded certificate and key from files
///
/// # Arguments
///
/// * `cert` - The path to the DER encoded certificate.
/// * `key` - The path to the DER encoded PKCS8 private key.
/// * `encoding` - The encoding of the certificate and key.
///
/// # Returns
///
/// * `Identity` - The new Identity instance.
///
fn from_pkcs8_file(cert: &str, key: &str, encoding: ContentEncoding) -> std::io::Result<Self>
where
Self: Sized;
}
/// Certificate
pub trait Certificate {
/// Create certificate from slice of DER encoded bytes.
///
/// # Arguments
///
/// * `data` - The client certificate data.
///
/// # Returns
///
/// * `Certificate` - The new Certificate instance.
///
fn from_slice(data: &[u8], encoding: ContentEncoding) -> Self;
/// Create certificate from file of DER encoded file.
///
/// # Arguments
///
/// * `file` - The client certificate file path.
///
/// # Returns
///
/// * `Result<Certificate, std::io::Error>` - The new Certificate instance.
///
fn from_file(file: &str, encoding: ContentEncoding) -> std::io::Result<Self>
where
Self: Sized;
/// Allow get the client certificate path.
///
/// # Returns
///
/// * `&str` - The client certificate path.
///
fn as_bytes(&self) -> &Vec<u8>;
}