Skip to main content

IdentityBuilder

Struct IdentityBuilder 

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

Generates a self-signed ECDSA P-256 identity without writing it: Identity::builder, the validity, then generate.

With nothing set the certificate is valid for rcgen’s default period (decades), as Identity::generate makes it. Every generated certificate has the common name coqui-peer, a DNS subjectAltName SERVER_NAME, a subjectKeyIdentifier and basicConstraints CA:FALSE. Peers pin it by fingerprint, so the name is not checked. Times are whole seconds: both are truncated.

The end of the validity is one setting: not_after and valid_for each set it, and the last one called wins.

For WebTransport’s serverCertificateHashes, which accepts only a certificate whose whole validity period is at most 14 days, use valid_for(Duration::from_secs(14 * 86_400)) at most and replace the identity before it expires; a peer whose clock runs behind sees it as not yet valid, so an earlier not_before, within the same 14 days, covers that.

The key algorithm is key_algorithm; the default is ECDSA P-256.

Implementations§

Source§

impl IdentityBuilder

Source

pub fn not_before(self, at: SystemTime) -> Self

The first instant the certificate is valid. Default rcgen’s.

Source

pub fn not_after(self, at: SystemTime) -> Self

The last instant the certificate is valid. Replaces valid_for.

Source

pub fn valid_for(self, validity: Duration) -> Self

How long the certificate is valid from not_before, from now when that is not set. Replaces not_after.

Source

pub fn key_algorithm(self, algorithm: KeyAlgorithm) -> Self

The key algorithm. Default KeyAlgorithm::P256.

Source

pub fn generate(self) -> Result<Identity, PeerError>

Generates the identity.

§Errors

PeerError::Certificate when valid_for is under one second, when not_after is not at least one second after not_before, when either is before 1970 or out of range, or when key generation fails.

Trait Implementations§

Source§

impl Clone for IdentityBuilder

Source§

fn clone(&self) -> Self

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 IdentityBuilder

Source§

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

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

impl Default for IdentityBuilder

Source§

fn default() -> Self

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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.