Skip to main content

sofie_client/
testing.rs

1use rustls::RootCertStore;
2use rustls::pki_types::CertificateDer;
3use sofie_core::{Error, Result};
4
5use crate::connect::Connector;
6use crate::{Outgoing, Vendor};
7
8/// Trusts only `root`, so a test server's certificate is trusted in that test and nowhere else.
9pub fn outgoing(vendor: &'static str, settings: Vendor, root: &[u8]) -> Result<Outgoing> {
10    let mut roots = RootCertStore::empty();
11    roots
12        .add(CertificateDer::from(root.to_vec()))
13        .map_err(|error| Error::internal("trusting the test's root certificate", error))?;
14    Outgoing::build(vendor, settings, Connector::trusting(roots))
15}