Skip to main content

Session

Struct Session 

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

One pairwise end-to-end encrypted conversation.

An accept alone never reaches SessionState::Established: the responder side lands in SessionState::AwaitingAck, which exposes no way to decrypt content, and only Session::receive_ack can move it onward. There is no method on this type that decrypts a msg/media payload from any other state, which is what makes the “accept is not established” rule a property of the API rather than a rule callers must remember to enforce.

Implementations§

Source§

impl Session

Source

pub fn new() -> Self

A session that has not started negotiating with anyone.

Source

pub fn start( &mut self, identity: &Identity, rng: &mut impl RandomSource, ) -> Result<PreKeyBundle, Error>

Start as the wire’s initiator: publish a fresh prekey bundle.

Source

pub fn receive_offer(&mut self, bundle: PreKeyBundle) -> Fingerprint

Record an inbound init, returning the offered (not yet verified or pinned) fingerprint for a pre-acceptance prompt.

When this side already has its own offer outstanding, the caller must resolve the crossing-offer tiebreak with keeps_own_offer before calling this: a side that keeps its own offer must not overwrite it by recording the peer’s.

Source

pub fn accept( &mut self, identity: &Identity, rng: &mut impl RandomSource, ) -> Result<HandshakeResponse, Error>

Accept a recorded offer: verify it, derive the session secret, and answer with a HandshakeResponse. Lands in SessionState::AwaitingAck, not established.

Source

pub fn reject(&mut self, reason: Option<String>) -> Frame

Reject a recorded offer.

Source

pub fn receive_reject(&mut self)

Record an inbound reject for an offer this side sent.

Source

pub fn receive_accept( &mut self, identity: &Identity, response: &HandshakeResponse, rng: &mut impl RandomSource, ) -> Result<(), Error>

Complete the handshake as the initiator: verify the responder’s signature before pinning its fingerprint, derive the session secret, and decrypt boot. Reaches SessionState::Established directly, since the initiator has no further frame to wait for.

Source

pub fn make_ack(&mut self) -> Result<RatchetMessage, Error>

Produce the initiator’s ack: an empty-plaintext ratchet message proving the session works.

Source

pub fn receive_ack( &mut self, ct: &RatchetMessage, rng: &mut impl RandomSource, ) -> Result<(), Error>

Decrypt the initiator’s ack. Only this call moves a responder from SessionState::AwaitingAck to SessionState::Established; a lost or not-yet-arrived ack leaves the session exactly where it was, never showing established early.

Source

pub fn send(&mut self, plaintext: &[u8]) -> Result<RatchetMessage, Error>

Encrypt a msg/media payload. Only available once established.

Source

pub fn receive( &mut self, ct: &RatchetMessage, rng: &mut impl RandomSource, ) -> Result<Vec<u8>, Error>

Decrypt a msg/media payload. Only available once established: there is no state from which this call can reach a receiving chain before then.

Source

pub fn close(&mut self) -> Frame

End the session locally.

Source

pub fn receive_close(&mut self)

Record an inbound close.

Source

pub const fn is_established(&self) -> bool

Whether this session can currently send or receive content.

Source

pub fn peer_fingerprint(&self) -> Option<Fingerprint>

The peer’s pinned fingerprint, once one has been observed.

Source

pub fn is_peer_verified(&self) -> bool

Whether the pinned fingerprint has been confirmed out of band.

Source

pub fn mark_peer_verified(&mut self)

Mark the pinned fingerprint as confirmed out of band.

Source

pub fn confirm_fingerprint_change(&mut self, fingerprint: Fingerprint)

Accept a fingerprint change the caller has explicitly decided to trust, so the operation that reported Error::FingerprintChanged can be retried and will succeed this time.

Source

pub const fn role(&self) -> Option<Role>

Which side of the handshake this session played, once negotiation has started.

Trait Implementations§

Source§

impl Default for Session

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
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.