Skip to main content

NativeTlsAcceptor

Struct NativeTlsAcceptor 

Source
pub struct NativeTlsAcceptor(/* private fields */);
Expand description

trillium Acceptor for native-tls

Implementations§

Source§

impl NativeTlsAcceptor

Source

pub fn new(t: impl Into<Self>) -> Self

constructs a NativeTlsAcceptor from a native_tls::TlsAcceptor, an async_native_tls::TlsAcceptor, or an Identity

Source

pub fn from_cert_and_key(cert: &[u8], key: &[u8]) -> Self

Construct a NativeTlsAcceptor from a PEM-encoded certificate chain and a PEM-encoded private key.

This is the recommended entrypoint and matches the input format used by trillium-rustls and trillium-openssl. The cert input may contain one or more CERTIFICATE blocks (the leaf followed by any intermediates). The key input is accepted in any of the three common PEM key forms:

  • -----BEGIN PRIVATE KEY----- (PKCS#8)
  • -----BEGIN RSA PRIVATE KEY----- (PKCS#1)
  • -----BEGIN EC PRIVATE KEY----- (SEC1)

Either argument may also be a single concatenated bundle containing both the cert chain and the key; the relevant blocks are extracted from each input. Encrypted keys are not supported here — decrypt first or use Self::from_pkcs12.

Internally we first try Identity::from_pkcs8 with the normalized PEM inputs; on backends that reject that import path (notably macOS Secure Transport, which refuses EC keys this way with errSecUnknownFormat), we fall back to packaging the cert chain and key into an in-memory PKCS#12 archive and calling Identity::from_pkcs12. The fallback only runs when the first attempt fails, so OpenSSL-backed platforms never hit it.

Windows + EC keys: SChannel rejects EC keys via both paths — its PKCS#8 PEM import is strict, and our fallback archive omits the LocalKeyId attribute SChannel uses to pair cert and key. For EC keys on Windows, prefer trillium-rustls, or supply a pre-built PKCS#12 archive (e.g. from openssl pkcs12 -export) via Self::from_pkcs12. RSA keys work on Windows.

§Example
use trillium_native_tls::NativeTlsAcceptor;
const CERT: &[u8] = include_bytes!("../tests/fixtures/rsa.crt");
const KEY: &[u8] = include_bytes!("../tests/fixtures/rsa-pkcs8.key");
let acceptor = NativeTlsAcceptor::from_cert_and_key(CERT, KEY);
Source

pub fn from_pkcs12(der: &[u8], password: &str) -> Self

Construct a NativeTlsAcceptor from a PKCS#12 archive and password.

PKCS#12 (.p12/.pfx) bundles a certificate chain and a private key in a single password-protected archive. Prefer Self::from_cert_and_key when you have separate cert and key PEM files, which is by far the more common provisioning format.

Source

pub fn from_pkcs8(pem: &[u8], key: &[u8]) -> Self

Construct a NativeTlsAcceptor directly from PKCS#8 PEM cert and key inputs, without normalization.

Prefer Self::from_cert_and_key, which accepts the same inputs plus PKCS#1 and SEC1 keys. This constructor is retained for backwards compatibility and forwards directly to Identity::from_pkcs8.

Trait Implementations§

Source§

impl<Input> Acceptor<Input> for NativeTlsAcceptor
where Input: Transport,

Source§

type Error = Error

An error type that Acceptor::accept may return
Source§

type Output = NativeTlsServerTransport<Input>

The stream type. For example, TlsStream<Input>
Source§

async fn accept(&self, input: Input) -> Result<Self::Output, Self::Error>

Transform an Input (AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static) into Self::Output
Source§

fn is_secure(&self) -> bool

should conns be treated as secure?
Source§

impl Clone for NativeTlsAcceptor

Source§

fn clone(&self) -> NativeTlsAcceptor

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NativeTlsAcceptor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<(&[u8], &str)> for NativeTlsAcceptor

Source§

fn from(i: (&[u8], &str)) -> Self

Converts to this type from the input type.
Source§

impl From<Identity> for NativeTlsAcceptor

Source§

fn from(i: Identity) -> Self

Converts to this type from the input type.
Source§

impl From<TlsAcceptor> for NativeTlsAcceptor

Source§

fn from(i: TlsAcceptor) -> Self

Converts to this type from the input type.
Source§

impl From<TlsAcceptor> for NativeTlsAcceptor

Source§

fn from(i: TlsAcceptor) -> Self

Converts to this type from the input type.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.