trz_gateway_common/security_configuration/certificate/
dynamic.rs1use std::sync::Arc;
3
4use openssl::x509::X509;
5use openssl::x509::store::X509Store;
6
7use super::CertificateConfig;
8use super::X509CertificateInfo;
9use crate::dynamic_config::DynamicConfig;
10use crate::dynamic_config::mode::Mode;
11use crate::security_configuration::trusted_store::TrustedStoreConfig;
12
13pub struct DynamicCertificate<C, M: Mode>(Arc<DynamicConfig<C, M>>);
15
16impl<C, M: Mode> From<Arc<DynamicConfig<C, M>>> for DynamicCertificate<C, M> {
17 fn from(value: Arc<DynamicConfig<C, M>>) -> Self {
18 Self(value)
19 }
20}
21
22impl<C: CertificateConfig, M: Mode> CertificateConfig for DynamicCertificate<C, M> {
23 type Error = C::Error;
24
25 fn intermediates(&self) -> Result<Arc<Vec<X509>>, Self::Error> {
26 self.0.with(|config| config.intermediates())
27 }
28
29 fn certificate(&self) -> Result<Arc<X509CertificateInfo>, Self::Error> {
30 self.0.with(|config| config.certificate())
31 }
32
33 fn is_dynamic(&self) -> bool {
34 true
35 }
36}
37
38impl<C: TrustedStoreConfig, M: Mode> TrustedStoreConfig for DynamicCertificate<C, M> {
39 type Error = C::Error;
40
41 fn root_certificates(&self) -> Result<Arc<X509Store>, Self::Error> {
42 self.0.with(|config| config.root_certificates())
43 }
44}
45
46impl<C: Clone + std::fmt::Debug, M: Mode> std::fmt::Debug for DynamicCertificate<C, M> {
47 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48 f.debug_tuple("DynamicCertificate")
49 .field(&self.0.get())
50 .finish()
51 }
52}