tlsn_core/config/
verifier.rs

1//! Verifier configuration.
2
3use serde::{Deserialize, Serialize};
4
5use crate::webpki::RootCertStore;
6
7/// Verifier configuration.
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct VerifierConfig {
10    root_store: RootCertStore,
11}
12
13impl VerifierConfig {
14    /// Creates a new builder.
15    pub fn builder() -> VerifierConfigBuilder {
16        VerifierConfigBuilder::default()
17    }
18
19    /// Returns the root certificate store.
20    pub fn root_store(&self) -> &RootCertStore {
21        &self.root_store
22    }
23}
24
25/// Builder for [`VerifierConfig`].
26#[derive(Debug, Default)]
27pub struct VerifierConfigBuilder {
28    root_store: Option<RootCertStore>,
29}
30
31impl VerifierConfigBuilder {
32    /// Sets the root certificate store.
33    pub fn root_store(mut self, root_store: RootCertStore) -> Self {
34        self.root_store = Some(root_store);
35        self
36    }
37
38    /// Builds the configuration.
39    pub fn build(self) -> Result<VerifierConfig, VerifierConfigError> {
40        let root_store = self
41            .root_store
42            .ok_or(ErrorRepr::MissingField { name: "root_store" })?;
43        Ok(VerifierConfig { root_store })
44    }
45}
46
47/// Error for [`VerifierConfig`].
48#[derive(Debug, thiserror::Error)]
49#[error(transparent)]
50pub struct VerifierConfigError(#[from] ErrorRepr);
51
52#[derive(Debug, thiserror::Error)]
53enum ErrorRepr {
54    #[error("missing field: {name}")]
55    MissingField { name: &'static str },
56}