use std::any::Any;
use std::borrow::Cow;
use std::sync::Arc;
#[derive(Clone, Debug)]
pub struct SslDigest {
pub cipher: Cow<'static, str>,
pub version: Cow<'static, str>,
pub organization: Option<String>,
pub serial_number: Option<String>,
pub cert_digest: Vec<u8>,
pub extension: SslDigestExtension,
}
impl SslDigest {
pub fn new<S>(
cipher: S,
version: S,
organization: Option<String>,
serial_number: Option<String>,
cert_digest: Vec<u8>,
) -> Self
where
S: Into<Cow<'static, str>>,
{
SslDigest {
cipher: cipher.into(),
version: version.into(),
organization,
serial_number,
cert_digest,
extension: SslDigestExtension::default(),
}
}
}
#[derive(Clone, Debug, Default)]
pub struct SslDigestExtension {
value: Option<Arc<dyn Any + Send + Sync>>,
}
impl SslDigestExtension {
pub fn get<T>(&self) -> Option<&T>
where
T: Send + Sync + 'static,
{
self.value.as_ref().and_then(|v| v.downcast_ref::<T>())
}
#[allow(dead_code)]
pub(crate) fn set(&mut self, value: Arc<dyn Any + Send + Sync>) {
self.value = Some(value);
}
}