tor_keymgr/keystore/arti/
certs.rs
1use std::path::PathBuf;
4
5use tor_error::internal;
6use tor_key_forge::{CertType, ParsedEd25519Cert};
7
8use crate::keystore::arti::err::ArtiNativeKeystoreError;
9use crate::{ErasedKey, Result};
10
11pub(super) struct UnparsedCert {
13 inner: Vec<u8>,
15 path: PathBuf,
17}
18
19impl UnparsedCert {
20 pub(super) fn new(inner: Vec<u8>, path: PathBuf) -> Self {
22 Self { inner, path }
23 }
24
25 pub(super) fn parse_certificate_erased(self, cert_type: &CertType) -> Result<ErasedKey> {
30 match cert_type {
31 CertType::Ed25519TorCert => {
32 let cert = ParsedEd25519Cert::decode(self.inner).map_err(|e| {
33 ArtiNativeKeystoreError::CertParse {
34 path: self.path,
35 cert_type: cert_type.clone(),
36 err: e.clone(),
37 }
38 })?;
39
40 Ok(Box::new(cert))
41 }
42 _ => Err(
43 ArtiNativeKeystoreError::Bug(internal!("Unknown cert type {cert_type:?}")).into(),
44 ),
45 }
46 }
47}