1 use std::fmt;
2 
3 /// This type contains a private key by value.
4 ///
5 /// The private key must be DER-encoded ASN.1 in either
6 /// PKCS#8 or PKCS#1 format.
7 ///
8 /// `rustls::pemfile::pkcs8_private_keys` or `rustls::pemfile::rsa_private_keys`
9 /// could be used to extract private keys from a PEM file in these formats.
10 #[derive(Debug, Clone, Eq, PartialEq)]
11 pub struct PrivateKey(pub Vec<u8>);
12 
13 /// This type contains a single certificate by value.
14 ///
15 /// The certificate must be DER-encoded X.509.
16 ///
17 /// `rustls::pemfile::certs` function can be used to parse a PEM file.
18 #[derive(Clone, Eq, PartialEq)]
19 pub struct Certificate(pub Vec<u8>);
20 
21 impl AsRef<[u8]> for Certificate {
as_ref(&self) -> &[u8]22     fn as_ref(&self) -> &[u8] {
23         &self.0
24     }
25 }
26 
27 impl fmt::Debug for Certificate {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result28     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
29         use super::bs_debug::BsDebug;
30         f.debug_tuple("Certificate")
31             .field(&BsDebug(&self.0))
32             .finish()
33     }
34 }
35 
36 #[cfg(test)]
37 mod test {
38     use super::Certificate;
39 
40     #[test]
certificate_debug()41     fn certificate_debug() {
42         assert_eq!(
43             "Certificate(b\"ab\")",
44             format!("{:?}", Certificate(b"ab".to_vec()))
45         );
46     }
47 }
48