feat: to_pem -> bytes_to_pem

This commit is contained in:
2022-04-04 16:05:55 +08:00
parent d90223a8ca
commit 8d988f5427
2 changed files with 25 additions and 24 deletions

View File

@@ -6,6 +6,29 @@ use sequoia_openpgp::crypto::mpi::PublicKey;
use crate::digest::sha256_bytes;
// pub fn to_pem(bs: &[u8], sub: &str, w: usize) -> String {
// let mut s = String::with_capacity(bs.len() * 2);
// s.push_str(&format!("-----BEGIN {}-----", sub));
// let b64 = base64::encode(bs).chars().collect::<Vec<char>>();
// let mut b64 = b64.as_slice();
// while !b64.is_empty() {
// s.push('\n');
// if b64.len() >= w {
// for c in b64.iter().take(w) {
// s.push(*c);
// }
// b64 = &b64[w..];
// } else {
// for c in b64 {
// s.push(*c);
// }
// b64 = &[];
// }
// }
// s.push_str(&format!("\n-----END {}-----", sub));
// s
// }
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(),