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
impl Peerstate
sourcepub fn from_header(header: &Aheader, message_time: i64) -> Self
pub fn from_header(header: &Aheader, message_time: i64) -> Self
Creates a peerstate from the Autocrypt
header.
sourcepub fn from_public_key(
addr: &str,
last_seen: i64,
prefer_encrypt: EncryptPreference,
public_key: &SignedPublicKey,
) -> Self
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.
sourcepub fn from_gossip(gossip_header: &Aheader, message_time: i64) -> Self
pub fn from_gossip(gossip_header: &Aheader, message_time: i64) -> Self
Create a peerstate from the Autocrypt-Gossip
header.
sourcepub async fn from_addr(
context: &Context,
addr: &str,
) -> Result<Option<Peerstate>>
pub async fn from_addr( context: &Context, addr: &str, ) -> Result<Option<Peerstate>>
Loads peerstate corresponding to the given address from the database.
sourcepub async fn from_fingerprint(
context: &Context,
fingerprint: &Fingerprint,
) -> Result<Option<Peerstate>>
pub async fn from_fingerprint( context: &Context, fingerprint: &Fingerprint, ) -> Result<Option<Peerstate>>
Loads peerstate corresponding to the given fingerprint from the database.
sourcepub async fn from_verified_fingerprint_or_addr(
context: &Context,
fingerprint: &Fingerprint,
addr: &str,
) -> Result<Option<Peerstate>>
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.
async fn from_stmt( context: &Context, query: &str, params: impl Params + Send, ) -> Result<Option<Peerstate>>
sourcepub fn recalc_fingerprint(&mut self)
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
.
sourcepub fn degrade_encryption(&mut self, message_time: i64)
pub fn degrade_encryption(&mut self, message_time: i64)
Reset Autocrypt peerstate.
Used when it is detected that the contact no longer uses Autocrypt.
sourcepub fn apply_header(
&mut self,
context: &Context,
header: &Aheader,
message_time: i64,
)
pub fn apply_header( &mut self, context: &Context, header: &Aheader, message_time: i64, )
Updates peerstate according to the given Autocrypt
header.
sourcepub fn apply_gossip(&mut self, gossip_header: &Aheader, message_time: i64)
pub fn apply_gossip(&mut self, gossip_header: &Aheader, message_time: i64)
Updates peerstate according to the given Autocrypt-Gossip
header.
sourcepub fn render_gossip_header(&self, verified: bool) -> Option<String>
pub fn render_gossip_header(&self, verified: bool) -> Option<String>
Returns the contents of the Autocrypt-Gossip
header for outgoing messages.
sourcepub fn take_key(self, verified: bool) -> Option<SignedPublicKey>
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.
sourcepub fn peek_key(&self, verified: bool) -> Option<&SignedPublicKey>
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.
sourcefn peek_key_fingerprint(&self, verified: bool) -> Option<&Fingerprint>
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.
sourcepub(crate) fn is_using_verified_key(&self) -> bool
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.
pub(crate) async fn is_backward_verified( &self, context: &Context, ) -> Result<bool>
sourcepub fn set_verified(
&mut self,
key: SignedPublicKey,
fingerprint: Fingerprint,
verifier: String,
) -> Result<()>
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.
sourcepub fn set_secondary_verified_key(
&mut self,
gossip_key: SignedPublicKey,
verifier: String,
)
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.
sourcepub async fn save_to_db(&self, sql: &Sql) -> Result<()>
pub async fn save_to_db(&self, sql: &Sql) -> Result<()>
Saves the peerstate to the database.
sourcepub(crate) async fn save_to_db_ex(
&self,
sql: &Sql,
old_addr: Option<&str>,
) -> Result<()>
pub(crate) async fn save_to_db_ex( &self, sql: &Sql, old_addr: Option<&str>, ) -> Result<()>
Saves the peerstate to the database.
old_addr
: Old address of the peerstate in case of an AEAP transition.
sourcepub fn get_verifier(&self) -> Option<&str>
pub fn get_verifier(&self) -> Option<&str>
Returns the address that verified the contact
sourceasync fn handle_setup_change(
&self,
context: &Context,
timestamp: i64,
change: PeerstateChange,
) -> Result<()>
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.
Trait Implementations§
impl Eq for Peerstate
impl StructuralPartialEq for Peerstate
Auto Trait Implementations§
impl Freeze for Peerstate
impl RefUnwindSafe for Peerstate
impl Send for Peerstate
impl Sync for Peerstate
impl Unpin for Peerstate
impl UnwindSafe for Peerstate
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.