pub struct Peerstate {
Show 17 fields pub addr: String, pub last_seen: i64, pub last_seen_autocrypt: i64, pub prefer_encrypt: EncryptPreference, pub public_key: Option<SignedPublicKey>, pub public_key_fingerprint: Option<Fingerprint>, pub gossip_key: Option<SignedPublicKey>, pub gossip_timestamp: i64, pub gossip_key_fingerprint: Option<Fingerprint>, pub verified_key: Option<SignedPublicKey>, pub verified_key_fingerprint: Option<Fingerprint>, pub verifier: Option<String>, pub secondary_verified_key: Option<SignedPublicKey>, pub secondary_verified_key_fingerprint: Option<Fingerprint>, pub secondary_verifier: Option<String>, pub backward_verified_key_id: Option<i64>, pub fingerprint_changed: bool,
}
Expand description

Peerstate represents the state of an Autocrypt peer.

Fields§

§addr: String

E-mail address of the contact.

§last_seen: i64

Timestamp of the latest peerstate update.

Updated when a message is received from a contact, either with or without Autocrypt header.

§last_seen_autocrypt: i64

Timestamp of the latest Autocrypt header reception.

§prefer_encrypt: EncryptPreference

Encryption preference of the contact.

§public_key: Option<SignedPublicKey>

Public key of the contact received in Autocrypt header.

§public_key_fingerprint: Option<Fingerprint>

Fingerprint of the contact public key.

§gossip_key: Option<SignedPublicKey>

Public key of the contact received in Autocrypt-Gossip header.

§gossip_timestamp: i64

Timestamp of the latest Autocrypt-Gossip header reception.

It is stored to avoid applying outdated gossiped key from delayed or reordered messages.

§gossip_key_fingerprint: Option<Fingerprint>

Fingerprint of the contact gossip key.

§verified_key: Option<SignedPublicKey>

Public key of the contact at the time it was verified, either directly or via gossip from the verified contact.

§verified_key_fingerprint: Option<Fingerprint>

Fingerprint of the verified public key.

§verifier: Option<String>

The address that introduced this verified key.

§secondary_verified_key: Option<SignedPublicKey>

Secondary public verified key of the contact. It could be a contact gossiped by another verified contact in a shared group or a key that was previously used as a verified key.

§secondary_verified_key_fingerprint: Option<Fingerprint>

Fingerprint of the secondary verified public key.

§secondary_verifier: Option<String>

The address that introduced secondary verified key.

§backward_verified_key_id: Option<i64>

Row ID of the key in the keypairs table that we think the peer knows as verified.

§fingerprint_changed: bool

True if it was detected that the fingerprint of the key used in chats with opportunistic encryption was changed after Peerstate creation.

Implementations§

source§

impl Peerstate

source

pub fn from_header(header: &Aheader, message_time: i64) -> Self

Creates a peerstate from the Autocrypt header.

source

pub fn from_public_key( addr: &str, last_seen: i64, prefer_encrypt: EncryptPreference, public_key: &SignedPublicKey ) -> Self

Creates a peerstate from the given public key.

source

pub fn from_gossip(gossip_header: &Aheader, message_time: i64) -> Self

Create a peerstate from the Autocrypt-Gossip header.

source

pub async fn from_addr( context: &Context, addr: &str ) -> Result<Option<Peerstate>>

Loads peerstate corresponding to the given address from the database.

source

pub async fn from_fingerprint( context: &Context, fingerprint: &Fingerprint ) -> Result<Option<Peerstate>>

Loads peerstate corresponding to the given fingerprint from the database.

source

pub async fn from_verified_fingerprint_or_addr( context: &Context, fingerprint: &Fingerprint, addr: &str ) -> Result<Option<Peerstate>>

Loads peerstate by address or verified fingerprint.

If the address is different but verified fingerprint is the same, peerstate with corresponding verified fingerprint is preferred.

source

async fn from_stmt( context: &Context, query: &str, params: impl Params + Send ) -> Result<Option<Peerstate>>

source

pub fn recalc_fingerprint(&mut self)

Re-calculate self.public_key_fingerprint and self.gossip_key_fingerprint. If one of them was changed, self.fingerprint_changed is set to true.

Call this after you changed self.public_key or self.gossip_key.

source

pub fn degrade_encryption(&mut self, message_time: i64)

Reset Autocrypt peerstate.

Used when it is detected that the contact no longer uses Autocrypt.

source

pub fn apply_header(&mut self, header: &Aheader, message_time: i64)

Updates peerstate according to the given Autocrypt header.

source

pub fn apply_gossip(&mut self, gossip_header: &Aheader, message_time: i64)

Updates peerstate according to the given Autocrypt-Gossip header.

source

pub fn render_gossip_header(&self, verified: bool) -> Option<String>

Returns the contents of the Autocrypt-Gossip header for outgoing messages.

source

pub fn take_key(self, verified: bool) -> Option<SignedPublicKey>

Converts the peerstate into the contact public key.

Similar to Self::peek_key, but consumes the peerstate and returns owned key.

source

pub fn peek_key(&self, verified: bool) -> Option<&SignedPublicKey>

Returns a reference to the contact public key.

verified determines the required verification status of the key. If verified key is requested, returns the verified key, otherwise returns the Autocrypt key.

Returned key is suitable for sending in Autocrypt-Gossip header.

Returns None if there is no suitable public key.

source

fn peek_key_fingerprint(&self, verified: bool) -> Option<&Fingerprint>

Returns a reference to the contact’s public key fingerprint.

Similar to Self::peek_key, but returns the fingerprint instead of the key.

source

pub(crate) fn is_using_verified_key(&self) -> bool

Returns true if the key used for opportunistic encryption in the 1:1 chat is the same as the verified key.

Note that verified groups always use the verified key no matter if the opportunistic key matches or not.

source

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

source

pub fn set_verified( &mut self, key: SignedPublicKey, fingerprint: Fingerprint, verifier: String ) -> Result<()>

Set this peerstate to verified; make sure to call self.save_to_db to save these changes.

Params:

  • key: The new verified key.
  • fingerprint: Only set to verified if the key’s fingerprint matches this.
  • verifier: The address which introduces the given contact. If we are verifying the contact, use that contacts address.
source

pub fn set_secondary_verified_key( &mut self, gossip_key: SignedPublicKey, verifier: String )

Sets the gossiped key as the secondary verified key.

If gossiped key is the same as the current verified key, do nothing to avoid overwriting secondary verified key which may be different.

source

pub async fn save_to_db(&self, sql: &Sql) -> Result<()>

Saves the peerstate to the database.

source

pub fn get_verifier(&self) -> Option<&str>

Returns the address that verified the contact

source

async fn handle_setup_change( &self, context: &Context, timestamp: i64, change: PeerstateChange ) -> Result<()>

Add an info message to all the chats with this contact, informing about a PeerstateChange.

Also, in the case of an address change (AEAP), replace the old address with the new address in all chats.

source

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

Adds a warning to all the chats corresponding to peerstate if fingerprint has changed.

Trait Implementations§

source§

impl Clone for Peerstate

source§

fn clone(&self) -> Peerstate

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 Peerstate

source§

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

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

impl PartialEq for Peerstate

source§

fn eq(&self, other: &Peerstate) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Peerstate

source§

impl StructuralEq for Peerstate

source§

impl StructuralPartialEq for Peerstate

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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