mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 19:06:35 +03:00
Make try_decrypt non-async
Private keyring is now loaded outside of try_decrypt
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
use anyhow::{Context as _, Result};
|
||||
use anyhow::Result;
|
||||
use mailparse::ParsedMail;
|
||||
|
||||
use crate::aheader::Aheader;
|
||||
@@ -24,9 +24,10 @@ use crate::pgp;
|
||||
/// signature fingerprints and whether the message is encrypted.
|
||||
///
|
||||
/// If the message is wrongly signed, HashSet will be empty.
|
||||
pub async fn try_decrypt(
|
||||
pub fn try_decrypt(
|
||||
context: &Context,
|
||||
mail: &ParsedMail<'_>,
|
||||
private_keyring: &Keyring<SignedSecretKey>,
|
||||
decryption_info: &DecryptionInfo,
|
||||
) -> Result<Option<(Vec<u8>, HashSet<Fingerprint>, bool)>> {
|
||||
// Possibly perform decryption
|
||||
@@ -45,13 +46,10 @@ pub async fn try_decrypt(
|
||||
Some(res) => res,
|
||||
};
|
||||
info!(context, "Detected Autocrypt-mime message");
|
||||
let private_keyring: Keyring<SignedSecretKey> = Keyring::new_self(context)
|
||||
.await
|
||||
.context("failed to get own keyring")?;
|
||||
|
||||
Ok(decrypt_part(
|
||||
encrypted_data_part,
|
||||
&private_keyring,
|
||||
private_keyring,
|
||||
public_keyring_for_validate,
|
||||
)?
|
||||
.map(|(raw, fprints)| (raw, fprints, true)))
|
||||
|
||||
@@ -23,7 +23,8 @@ use crate::dehtml::dehtml;
|
||||
use crate::events::EventType;
|
||||
use crate::format_flowed::unformat_flowed;
|
||||
use crate::headerdef::{HeaderDef, HeaderDefMap};
|
||||
use crate::key::{DcKey, Fingerprint, SignedPublicKey};
|
||||
use crate::key::{DcKey, Fingerprint, SignedPublicKey, SignedSecretKey};
|
||||
use crate::keyring::Keyring;
|
||||
use crate::message::{self, Viewtype};
|
||||
use crate::param::{Param, Params};
|
||||
use crate::peerstate::Peerstate;
|
||||
@@ -220,6 +221,9 @@ impl MimeMessage {
|
||||
headers.remove("chat-verified");
|
||||
|
||||
let from = from.context("No from in message")?;
|
||||
let private_keyring: Keyring<SignedSecretKey> = Keyring::new_self(context)
|
||||
.await
|
||||
.context("failed to get own keyring")?;
|
||||
let mut decryption_info =
|
||||
prepare_decryption(context, &mail, &from.addr, message_time).await?;
|
||||
|
||||
@@ -231,7 +235,7 @@ impl MimeMessage {
|
||||
hop_info += &decryption_info.dkim_results.to_string();
|
||||
|
||||
let (mail, mut signatures, encrypted) =
|
||||
match try_decrypt(context, &mail, &decryption_info).await {
|
||||
match try_decrypt(context, &mail, &private_keyring, &decryption_info) {
|
||||
Ok(Some((raw, signatures, encrypted))) => {
|
||||
// Only if `encrypted` and `signatures` set is non-empty, it is a valid
|
||||
// autocrypt message.
|
||||
|
||||
Reference in New Issue
Block a user