Skip to main content

CustomTransportBuilder

Struct CustomTransportBuilder 

Source
pub struct CustomTransportBuilder { /* private fields */ }
Expand description

Builder for a TransportConfig with multi-root trust chains and optional mTLS client certificate (bd:JMAP-6r7c.65).

CustomCaTransport is single-root and has no mTLS support; the builder is the richer-configuration counterpart. Common cases:

  • Private PKI with root + intermediate. Add both via add_root_pem (single cert) or add_roots_pem_bundle (bundle of roots + intermediates).
  • Mutual TLS. Add a client cert + key via with_client_cert.
  • Both. Compose freely; the builder is chainable.

Like CustomCaTransport, the resulting transport replaces the bundled webpki-roots with the configured trust roots. A “hybrid” deployment that wants both the bundled public roots AND custom roots is not currently supported; implement TransportConfig directly with the additive behaviour (reqwest::ClientBuilder::add_root_certificate is additive by default — a hand-rolled impl that omits .tls_built_in_root_certs(false) keeps the bundled roots).

§Usage

use jmap_base_client::auth::CustomTransportBuilder;

let transport = CustomTransportBuilder::new()
    .add_root_pem(&std::fs::read("ca-root.pem")?)?
    .add_root_pem(&std::fs::read("ca-intermediate.pem")?)?
    .with_client_cert(
        std::fs::read("client.pem")?,
        std::fs::read("client.key.pem")?,
    )
    .build();

let client = JmapClient::new(
    transport,
    BearerAuth::new(token)?,
    "https://internal-jmap.corp",
    ClientConfig::default(),
)?;

Implementations§

Source§

impl CustomTransportBuilder

Source

pub fn new() -> Self

Construct an empty builder. A builder with no trust roots and no client identity will produce a transport that rejects every TLS connection (no trust roots configured); add at least one root before build.

Source

pub fn add_root_der(self, der: Vec<u8>) -> Self

Add a DER-encoded trust-root certificate.

Validation of the DER bytes is deferred to build (same posture as CustomCaTransport::new). Invalid DER surfaces as ClientError::Http at JmapClient::new time.

Source

pub fn add_root_pem(self, pem: &[u8]) -> Result<Self, ClientError>

Add a PEM-encoded trust-root certificate. The first PEM-framed certificate in pem is consumed; embedded chains require add_roots_pem_bundle.

§Errors

Returns ClientError::InvalidArgument if pem does not contain a recognisable PEM-framed certificate.

Source

pub fn add_roots_pem_bundle( self, pem_bundle: &[u8], ) -> Result<Self, ClientError>

Add every PEM-framed certificate in a multi-cert bundle.

A typical private-PKI deployment ships a bundle containing the root plus one or more intermediates as concatenated PEM blocks. This method iterates each -----BEGIN CERTIFICATE----- block in input order and adds each to the trust set.

§Errors

Returns ClientError::InvalidArgument if no PEM-framed certificate is found in the bundle.

Source

pub fn with_client_cert(self, cert_pem: Vec<u8>, key_pem: Vec<u8>) -> Self

Configure a client certificate + private key for mutual TLS.

Replaces any previously-configured client identity. The two PEM byte slices are stored verbatim and concatenated at build time into a single PEM bundle that reqwest::Identity::from_pem consumes.

cert_pem may contain a single client cert or a cert + intermediates chain. key_pem carries the private key (PKCS#1 or PKCS#8, RSA or ECDSA — whatever reqwest’s rustls build supports).

Source

pub fn build(self) -> BuilderTransport

Consume the builder and return a TransportConfig implementation that produces a reqwest::Client configured with the accumulated trust roots and optional client identity.

Behaves identically to CustomCaTransport::build_client for single-root use; the additional functionality (multi-root + mTLS) kicks in when the builder was configured with more than one root or a client identity.

Trait Implementations§

Source§

impl Default for CustomTransportBuilder

Source§

fn default() -> CustomTransportBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more