From 380f6e278635c7742aaa71dd7e6ba969ffffd72e Mon Sep 17 00:00:00 2001 From: Hocuri Date: Mon, 15 Sep 2025 17:34:41 +0200 Subject: [PATCH] Some more small things I found while self-rewiewing --- src/decrypt.rs | 2 +- src/internals_for_benchmarks.rs | 7 +++---- src/mimefactory.rs | 3 +++ src/pgp.rs | 10 +++++----- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/decrypt.rs b/src/decrypt.rs index 060e87344..4012a8f41 100644 --- a/src/decrypt.rs +++ b/src/decrypt.rs @@ -10,7 +10,7 @@ use crate::pgp; /// Tries to decrypt a message, but only if it is structured as an Autocrypt message. /// -/// If successful and the message is encrypted, +/// If successful and the message was encrypted, /// returns the decrypted and decompressed message. pub fn try_decrypt<'a>( mail: &'a ParsedMail<'a>, diff --git a/src/internals_for_benchmarks.rs b/src/internals_for_benchmarks.rs index d08bd0842..50468c80e 100644 --- a/src/internals_for_benchmarks.rs +++ b/src/internals_for_benchmarks.rs @@ -9,16 +9,15 @@ use crate::context::Context; use crate::key; use crate::key::DcKey; use crate::mimeparser::MimeMessage; -pub use crate::pgp; - -use self::pgp::KeyPair; +use crate::pgp; +use crate::pgp::KeyPair; pub fn key_from_asc(data: &str) -> Result { key::SignedSecretKey::from_asc(data) } pub async fn store_self_keypair(context: &Context, keypair: &KeyPair) -> Result<()> { - crate::key::store_self_keypair(context, keypair).await + key::store_self_keypair(context, keypair).await } pub async fn parse_and_get_text(context: &Context, imf_raw: &[u8]) -> Result { diff --git a/src/mimefactory.rs b/src/mimefactory.rs index 75a253482..c8adac04a 100644 --- a/src/mimefactory.rs +++ b/src/mimefactory.rs @@ -1921,6 +1921,9 @@ fn should_encrypt_with_auth_token(msg: &Message) -> bool { fn should_encrypt_with_broadcast_secret(msg: &Message, chat: &Chat) -> bool { chat.typ == Chattype::OutBroadcast + // The only `SystemMessage::SecurejoinMessage` that is ever sent into a broadcast, + // which is `vb-request-with-auth`, + // should be encrypted with the AUTH token rather than the broadcast secret. && msg.param.get_cmd() != SystemMessage::SecurejoinMessage // The member-added message in a broadcast must be asymmetrically encrypted, // because the newly-added member doesn't know the broadcast shared secret yet: diff --git a/src/pgp.rs b/src/pgp.rs index db4846263..1d17ba1cb 100644 --- a/src/pgp.rs +++ b/src/pgp.rs @@ -232,11 +232,11 @@ pub fn pk_calc_signature( Ok(sig.to_armored_string(ArmorOptions::default())?) } -/// Decrypts the message with keys from the private key keyring. -/// -/// Receiver private keys are passed in `private_keys_for_decryption`, -/// shared secrets used for symmetric encryption -/// are passed in `shared_secrets`. +/// Decrypts the message: +/// - with keys from the private key keyring (passed in `private_keys_for_decryption`) +/// if the message was asymmetrically encrypted, +/// - with a shared secret/password (passed in `shared_secrets`), +/// if the message was symmetrically encrypted. /// /// Returns the decrypted and decompressed message. pub fn decrypt(