blob: f3639efb0dd65dea1aff7440168c2c388ffe17c9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
//! Helpers for encoding certificate material.
use crate::{CertType, ErasedKey, Result};
use tor_cert::EncodedEd25519Cert;
/// A key certificate.
#[derive(Clone, Debug)]
#[non_exhaustive]
pub enum CertData {
/// A tor-specific ed25519 cert.
TorEd25519Cert(EncodedEd25519Cert),
}
impl CertData {
/// Convert the cert material into a known cert type,
/// and return the type-erased value.
///
/// The caller is expected to downcast the value returned to the correct concrete type.
#[allow(clippy::unnecessary_wraps)]
pub(crate) fn into_erased(self) -> Result<ErasedKey> {
match self {
Self::TorEd25519Cert(cert) => Ok(Box::new(cert)),
}
}
/// Get the [`CertType`] of this cert.
pub(crate) fn cert_type(&self) -> CertType {
match self {
CertData::TorEd25519Cert(_) => CertType::Ed25519TorCert,
}
}
}
|