Skip to main content

Dtls

Struct Dtls 

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

Sans-IO DTLS endpoint (client or server).

New instances start in the server role. Call set_active(true) to switch to client before the handshake begins.

Drive the state machine with handle_packet, poll_output, and handle_timeout.

Implementations§

Source§

impl Dtls

Source

pub fn new_12( config: Arc<Config>, certificate: DtlsCertificate, now: Instant, ) -> Self

Create a new DTLS 1.2 instance in the server role.

Call set_active(true) to switch to client before the handshake begins. The now parameter seeds the internal time tracking for timeouts and retransmissions.

During the handshake, the peer’s leaf certificate is surfaced via Output::PeerCert. It is up to the application to validate that certificate according to its security policy.

Source

pub fn new_13( config: Arc<Config>, certificate: DtlsCertificate, now: Instant, ) -> Self

Create a new DTLS 1.3 instance in the server role.

Call set_active(true) to switch to client before the handshake begins.

During the handshake, the peer’s leaf certificate is surfaced via Output::PeerCert. It is up to the application to validate that certificate according to its security policy.

Source

pub fn new_auto( config: Arc<Config>, certificate: DtlsCertificate, now: Instant, ) -> Self

Create a new DTLS instance that auto‑senses the version.

Server role (default): the instance stays in a pending state. When the first ClientHello arrives it inspects the supported_versions extension and creates either a DTLS 1.2 or 1.3 server.

Client role (set_active(true)): the instance sends a hybrid ClientHello compatible with both DTLS 1.2 and 1.3 servers and forks into the correct handshake once the server responds.

Source

pub fn protocol_version(&self) -> Option<ProtocolVersion>

Returns the negotiated DTLS protocol version.

Returns None for auto-sense instances that have not yet completed version negotiation (i.e. still in a Pending state).

Source

pub fn is_active(&self) -> bool

Return true if the instance is operating in the client role.

Source

pub fn set_active(&mut self, active: bool)

Switch between server and client roles.

Set active to true for client role, false for server role.

When called on an auto‑sense instance (Dtls::new_auto) the client sends a hybrid ClientHello compatible with both DTLS 1.2 and 1.3. The version is determined from the server’s first response.

Source

pub fn handle_packet(&mut self, packet: &[u8]) -> Result<(), Error>

Process an incoming DTLS datagram.

Source

pub fn poll_output<'a>(&mut self, buf: &'a mut [u8]) -> Output<'a>

Poll for pending output from the DTLS engine.

Source

pub fn handle_timeout(&mut self, now: Instant) -> Result<(), Error>

Handle time-based events such as retransmission timers.

Source

pub fn send_application_data(&mut self, data: &[u8]) -> Result<(), Error>

Send application data over the established DTLS session.

Returns Error::HandshakePending if the DTLS version has not yet been resolved (auto-sense pending). Callers should buffer the data externally and retry after the handshake progresses.

Trait Implementations§

Source§

impl Debug for Dtls

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Dtls

§

impl RefUnwindSafe for Dtls

§

impl Send for Dtls

§

impl Sync for Dtls

§

impl Unpin for Dtls

§

impl UnsafeUnpin for Dtls

§

impl UnwindSafe for Dtls

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, 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, 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> CryptoSafe for T