feat: CTAP/FIDO cert

This commit is contained in:
2021-07-03 06:28:38 +08:00
parent 1e3fa35bdf
commit 9c2cc1d3f3
2 changed files with 62 additions and 41 deletions

View File

@@ -59,4 +59,27 @@ pub fn start_status_updater() -> Sender<StatusUpdate> {
}
});
status_tx
}
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.len() > 0 {
s.push('\n');
if b64.len() >= w {
for i in 0..w {
s.push(b64[i]);
}
b64 = &b64[w..];
} else {
for c in b64 {
s.push(*c);
}
b64 = &[];
}
}
s.push_str(&format!("\n-----END {}-----", sub));
s
}