binstalk_downloader/remote/
certificate.rs

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
#[cfg(feature = "__tls")]
use reqwest::tls;

use super::Error;

#[derive(Clone, Debug)]
pub struct Certificate(#[cfg(feature = "__tls")] pub(super) tls::Certificate);

#[cfg_attr(not(feature = "__tls"), allow(unused_variables))]
impl Certificate {
    /// Create a Certificate from a binary DER encoded certificate
    pub fn from_der(der: impl AsRef<[u8]>) -> Result<Self, Error> {
        #[cfg(not(feature = "__tls"))]
        return Ok(Self());

        #[cfg(feature = "__tls")]
        tls::Certificate::from_der(der.as_ref())
            .map(Self)
            .map_err(Error::from)
    }

    /// Create a Certificate from a PEM encoded certificate
    pub fn from_pem(pem: impl AsRef<[u8]>) -> Result<Self, Error> {
        #[cfg(not(feature = "__tls"))]
        return Ok(Self());

        #[cfg(feature = "__tls")]
        tls::Certificate::from_pem(pem.as_ref())
            .map(Self)
            .map_err(Error::from)
    }
}