diff --git a/CHANGELOG.md b/CHANGELOG.md index b1ab928cd..49bce56dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - fix verifier-by addr was empty string intead of None #3961 - Emit DC_EVENT_MSGS_CHANGED for DC_CHAT_ID_ARCHIVED_LINK when the number of archived chats with unread messages increases #3959 +- Fix Peerstate comparison #3962 ### API-Changes - jsonrpc: add verified-by information to `Contact`-Object diff --git a/src/contact.rs b/src/contact.rs index 95a713b5b..33b51ab8e 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -2628,4 +2628,27 @@ Hi."#; Ok(()) } + + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + async fn test_verified_by_none() -> Result<()> { + let mut tcm = TestContextManager::new(); + let alice = tcm.alice().await; + let bob = tcm.bob().await; + + let contact_id = Contact::create(&alice, "Bob", "bob@example.net").await?; + let contact = Contact::get_by_id(&alice, contact_id).await?; + assert!(contact.get_verifier_addr(&alice).await?.is_none()); + assert!(contact.get_verifier_id(&alice).await?.is_none()); + + // Receive a message from Bob to create a peerstate. + let chat = bob.create_chat(&alice).await; + let sent_msg = bob.send_text(chat.id, "moin").await; + alice.recv_msg(&sent_msg).await; + + let contact = Contact::get_by_id(&alice, contact_id).await?; + assert!(contact.get_verifier_addr(&alice).await?.is_none()); + assert!(contact.get_verifier_id(&alice).await?.is_none()); + + Ok(()) + } } diff --git a/src/peerstate.rs b/src/peerstate.rs index d0b9f335d..0c54d80c5 100644 --- a/src/peerstate.rs +++ b/src/peerstate.rs @@ -3,7 +3,6 @@ #![allow(missing_docs)] use std::collections::HashSet; -use std::fmt; use crate::aheader::{Aheader, EncryptPreference}; use crate::chat::{self, Chat}; @@ -35,6 +34,7 @@ pub enum PeerstateVerifiedStatus { } /// Peerstate represents the state of an Autocrypt peer. +#[derive(Debug, PartialEq, Eq)] pub struct Peerstate { pub addr: String, pub last_seen: i64, @@ -52,44 +52,6 @@ pub struct Peerstate { pub verifier: Option, } -impl PartialEq for Peerstate { - fn eq(&self, other: &Peerstate) -> bool { - self.addr == other.addr - && self.last_seen == other.last_seen - && self.last_seen_autocrypt == other.last_seen_autocrypt - && self.prefer_encrypt == other.prefer_encrypt - && self.public_key == other.public_key - && self.public_key_fingerprint == other.public_key_fingerprint - && self.gossip_key == other.gossip_key - && self.gossip_timestamp == other.gossip_timestamp - && self.gossip_key_fingerprint == other.gossip_key_fingerprint - && self.verified_key == other.verified_key - && self.verified_key_fingerprint == other.verified_key_fingerprint - && self.fingerprint_changed == other.fingerprint_changed - } -} - -impl Eq for Peerstate {} - -impl fmt::Debug for Peerstate { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_struct("Peerstate") - .field("addr", &self.addr) - .field("last_seen", &self.last_seen) - .field("last_seen_autocrypt", &self.last_seen_autocrypt) - .field("prefer_encrypt", &self.prefer_encrypt) - .field("public_key", &self.public_key) - .field("public_key_fingerprint", &self.public_key_fingerprint) - .field("gossip_key", &self.gossip_key) - .field("gossip_timestamp", &self.gossip_timestamp) - .field("gossip_key_fingerprint", &self.gossip_key_fingerprint) - .field("verified_key", &self.verified_key) - .field("verified_key_fingerprint", &self.verified_key_fingerprint) - .field("fingerprint_changed", &self.fingerprint_changed) - .finish() - } -} - impl Peerstate { pub fn from_header(header: &Aheader, message_time: i64) -> Self { Peerstate { @@ -458,7 +420,7 @@ impl Peerstate { self.verified_key.as_ref().map(|k| k.to_bytes()), self.verified_key_fingerprint.as_ref().map(|fp| fp.hex()), self.addr, - self.verifier, + self.verifier.as_deref().unwrap_or(""), ], ) .await?;