feat: byte_to_pem
This commit is contained in:
@@ -6,6 +6,14 @@ use sequoia_openpgp::crypto::mpi::PublicKey;
|
||||
|
||||
use crate::digest::sha256_bytes;
|
||||
|
||||
pub fn bytes_to_pem<T>(tag: &str, contents: T) -> String where T: Into<Vec<u8>> {
|
||||
let cert_public_key_pem_obj = Pem {
|
||||
tag: tag.to_string(),
|
||||
contents: contents.into(),
|
||||
};
|
||||
pem::encode(&cert_public_key_pem_obj).trim().to_string()
|
||||
}
|
||||
|
||||
pub fn sequoia_openpgp_public_key_pem(public_key: &PublicKey) -> Option<(Vec<u8>, String)> {
|
||||
match public_key {
|
||||
PublicKey::RSA { e, n } => {
|
||||
@@ -37,9 +45,5 @@ fn internal_rsa_public_key_pem(n: &[u8], e: &[u8]) -> (Vec<u8>, String) {
|
||||
);
|
||||
let rsa_pub_key_bytes = rsa_pub_key.unwrap().public_key_to_der().unwrap();
|
||||
let rsa_pub_key_bytes_sha256 = sha256_bytes(&rsa_pub_key_bytes);
|
||||
let pub_key_pem_obj = Pem {
|
||||
tag: String::from("PUBLIC KEY"),
|
||||
contents: rsa_pub_key_bytes,
|
||||
};
|
||||
(rsa_pub_key_bytes_sha256, pem::encode(&pub_key_pem_obj))
|
||||
(rsa_pub_key_bytes_sha256, bytes_to_pem("PUBLIC KEY", rsa_pub_key_bytes))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user