INNER CODE UNIT · Rust

parse_ssl_cert

DeterminateSystems/nix-installer · src/lib.rs:128

async fn parse_ssl_cert(ssl_cert_file: &Path) -> Result<Certificate, CertificateError> {
    let cert_buf = tokio::fs::read(ssl_cert_file)
        .await
        .map_err(|e| CertificateError::Read(ssl_cert_file.to_path_buf(), e))?;
    // We actually try them since things could be `.crt` and `pem` format or `der` format
    let cert = if let Ok(cert) = Certificate::from_pem(cert_buf.as_slice()) {
        cert
    } else if let Ok(cert) = Certificate::from_der(cert_buf.as_slice()) {
        cert
    } else {
        return Err(CertificateError::UnknownCertFormat);
    };
    Ok(cert)
}

#[derive(Debug, thiserror::Error)]
pub enum CertificateError {
    #[error(transparent)]

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…