Skip to content

Commit

Permalink
feat: add functions for converting DER to PEM
Browse files Browse the repository at this point in the history
  • Loading branch information
dufkan committed Mar 17, 2024
1 parent 7dc5e14 commit e63d702
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,14 @@ pub fn cert_key_to_pkcs12(key_der: &[u8], cert_der: &[u8]) -> Result<Vec<u8>, Er
.build2("")?
.to_der()
}


pub fn cert_der_to_pem(certificate: &[u8]) -> Vec<u8> {
let cert = openssl::x509::X509::from_der(certificate).unwrap();
cert.to_pem().unwrap()
}

pub fn key_der_to_pem(key: &[u8]) -> Vec<u8> {
let key = openssl::pkey::PKey::private_key_from_der(key).unwrap();
key.private_key_to_pem_pkcs8().unwrap()
}

0 comments on commit e63d702

Please sign in to comment.