pub struct BobState {
    id: i64,
    invite: QrInvite,
    next: SecureJoinStep,
    chat_id: ChatId,
}
Expand description

The securejoin state kept while Bob is joining.

This is stored in the database and loaded from there using BobState::from_db. To create a new one use BobState::start_protocol.

This purposefully has nothing optional, the state is always fully valid. However once a terminal state is reached in BobState::next the entry in the database will already have been deleted.

§Conducting the securejoin handshake

The methods on this struct allow you to interact with the state and thus conduct the securejoin handshake for Bob. The methods only concern themselves with the protocol state and explicitly avoid performing any user interactions required by securejoin. This simplifies the concerns and logic required in both the callers and in the state management. The return values can be used to understand what user interactions need to happen.

Fields§

§id: i64

Database primary key.

§invite: QrInvite

The QR Invite code.

§next: SecureJoinStep

The next expected message from Alice.

§chat_id: ChatId

The ChatId of the 1:1 chat with Alice, matching QrInvite::contact_id.

Implementations§

source§

impl BobState

Private implementations for user interactions about this BobState.

source

fn is_join_group(&self) -> bool

source

pub(crate) fn emit_progress(&self, context: &Context, progress: JoinerProgress)

source

async fn joining_chat_id(&self, context: &Context) -> Result<ChatId>

Returns the ChatId of the chat being joined.

This is the chat in which you want to notify the user as well.

When joining a group this is the ChatId of the group chat, when verifying a contact this is the ChatId of the 1:1 chat. The 1:1 chat is assumed to exist because a BobState can not exist without, the group chat will be created if it does not yet exist.

source

async fn notify_aborted(&self, context: &Context, why: &str) -> Result<()>

Notifies the user that the SecureJoin was aborted.

This creates an info message in the chat being joined.

source

pub(crate) async fn set_peer_verified( &self, context: &Context, timestamp: i64 ) -> Result<()>

Turns 1:1 chat with SecureJoin peer into protected chat.

source§

impl BobState

source

pub async fn start_protocol( context: &Context, invite: QrInvite, chat_id: ChatId ) -> Result<(Self, BobHandshakeStage, Vec<Self>)>

Starts the securejoin protocol and creates a new BobState.

The chat_id needs to be the ID of the 1:1 chat with Alice, this chat will be used to exchange the SecureJoin handshake messages as well as for showing error messages.

§Bob - the joiner’s side
§Step 2 in the “Setup Contact protocol”, section 2.1 of countermitm 0.10.0

This currently aborts any other securejoin process if any did not yet complete. The ChatIds of the relevant 1:1 chat of any aborted handshakes are returned so that you can report the aboreted handshake in the chat. (Yes, there can only ever be one ChatId in that Vec, the database doesn’t care though.)

source

async fn insert_new_db_entry( context: &Context, next: SecureJoinStep, invite: QrInvite, chat_id: ChatId ) -> Result<(i64, Vec<Self>)>

Inserts a new entry in the bobstate table, deleting all previous entries.

Returns the ID of the newly inserted entry and all the aborted states.

source

pub async fn from_db(sql: &Sql) -> Result<Option<Self>>

Load BobState from the database.

source

fn from_db_id(connection: &Connection, id: i64) -> Result<Self>

source

pub fn invite(&self) -> &QrInvite

Returns the QrInvite used to create this BobState.

source

pub fn alice_chat(&self) -> ChatId

Returns the ChatId of the 1:1 chat with the inviter (Alice).

source

async fn update_next(&mut self, sql: &Sql, next: SecureJoinStep) -> Result<()>

Updates the BobState::next field in memory and the database.

If the next state is a terminal state it will remove this BobState from the database.

If a user scanned a new QR code after this BobState was loaded this update will fail currently because starting a new joiner process currently kills any previously running processes. This is a limitation which will go away in the future.

source

pub(crate) async fn handle_auth_required( &mut self, context: &Context, mime_message: &MimeMessage ) -> Result<Option<BobHandshakeStage>>

Handles {vc,vg}-auth-required message of the securejoin handshake for Bob.

If the message was not used for this handshake None is returned, otherwise the new stage is returned. Once BobHandshakeStage::Terminated is reached this BobState should be destroyed, further calling it will just result in the messages being unused by this handshake.

source

pub(crate) fn is_msg_expected(&self, context: &Context, step: &str) -> bool

Returns true if the message is expected according to the protocol.

source

pub(crate) async fn step_contact_confirm( &mut self, context: &Context ) -> Result<()>

Handles a vc-contact-confirm or vg-member-added message.

§Bob - the joiner’s side
§Step 7 in the “Setup Contact protocol”, section 2.1 of countermitm 0.10.0
source

async fn send_handshake_message( &self, context: &Context, step: BobHandshakeMsg ) -> Result<()>

Sends the requested handshake message to Alice.

This takes care of adding the required headers for the step.

Trait Implementations§

source§

impl Clone for BobState

source§

fn clone(&self) -> BobState

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for BobState

source§

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

Formats the value using the given formatter. 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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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

§

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

§

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

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
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