mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 08:56:30 +03:00
name remaining blocking tasks
This commit is contained in:
@@ -353,9 +353,8 @@ async fn start(args: Vec<String>) -> Result<(), Error> {
|
|||||||
|
|
||||||
match readline {
|
match readline {
|
||||||
Ok(line) => {
|
Ok(line) => {
|
||||||
// TODO: ignore "set mail_pw"
|
|
||||||
rl.add_history_entry(line.as_str())?;
|
rl.add_history_entry(line.as_str())?;
|
||||||
let should_continue = Handle::current().block_on(async {
|
let should_continue = spawn_named_blocking_task!("repl:handle_cmd", async {
|
||||||
match handle_cmd(line.trim(), ctx.clone(), &mut selected_chat).await {
|
match handle_cmd(line.trim(), ctx.clone(), &mut selected_chat).await {
|
||||||
Ok(ExitResult::Continue) => true,
|
Ok(ExitResult::Continue) => true,
|
||||||
Ok(ExitResult::Exit) => {
|
Ok(ExitResult::Exit) => {
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ use pgp::composed::Deserializable;
|
|||||||
pub use pgp::composed::{SignedPublicKey, SignedSecretKey};
|
pub use pgp::composed::{SignedPublicKey, SignedSecretKey};
|
||||||
use pgp::ser::Serialize;
|
use pgp::ser::Serialize;
|
||||||
use pgp::types::{KeyTrait, SecretKeyTrait};
|
use pgp::types::{KeyTrait, SecretKeyTrait};
|
||||||
use tokio::runtime::Handle;
|
|
||||||
|
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::constants::KeyGenType;
|
use crate::constants::KeyGenType;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::log::LogExt;
|
use crate::log::LogExt;
|
||||||
use crate::pgp::KeyPair;
|
use crate::pgp::KeyPair;
|
||||||
|
use crate::spawn_named_blocking_task;
|
||||||
use crate::tools::{self, time_elapsed};
|
use crate::tools::{self, time_elapsed};
|
||||||
|
|
||||||
/// Convenience trait for working with keys.
|
/// Convenience trait for working with keys.
|
||||||
@@ -251,9 +251,10 @@ async fn generate_keypair(context: &Context) -> Result<KeyPair> {
|
|||||||
let keytype = KeyGenType::from_i32(context.get_config_int(Config::KeyGenType).await?)
|
let keytype = KeyGenType::from_i32(context.get_config_int(Config::KeyGenType).await?)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
info!(context, "Generating keypair with type {}", keytype);
|
info!(context, "Generating keypair with type {}", keytype);
|
||||||
// TODO? add it here as well?
|
let keypair =
|
||||||
let keypair = Handle::current()
|
spawn_named_blocking_task!("generate_keypair", move || crate::pgp::create_keypair(
|
||||||
.spawn_blocking(move || crate::pgp::create_keypair(addr, keytype))
|
addr, keytype
|
||||||
|
))
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
store_self_keypair(context, &keypair, KeyPairUse::Default).await?;
|
store_self_keypair(context, &keypair, KeyPairUse::Default).await?;
|
||||||
|
|||||||
42
src/pgp.rs
42
src/pgp.rs
@@ -251,34 +251,32 @@ pub async fn pk_encrypt(
|
|||||||
) -> Result<String> {
|
) -> Result<String> {
|
||||||
let lit_msg = Message::new_literal_bytes("", plain);
|
let lit_msg = Message::new_literal_bytes("", plain);
|
||||||
|
|
||||||
// TODO? label this
|
spawn_named_blocking_task("pk_encrypt", move || {
|
||||||
Handle::current()
|
let pkeys: Vec<SignedPublicKeyOrSubkey> = public_keys_for_encryption
|
||||||
.spawn_blocking(move || {
|
.iter()
|
||||||
let pkeys: Vec<SignedPublicKeyOrSubkey> = public_keys_for_encryption
|
.filter_map(select_pk_for_encryption)
|
||||||
.iter()
|
.collect();
|
||||||
.filter_map(select_pk_for_encryption)
|
let pkeys_refs: Vec<&SignedPublicKeyOrSubkey> = pkeys.iter().collect();
|
||||||
.collect();
|
|
||||||
let pkeys_refs: Vec<&SignedPublicKeyOrSubkey> = pkeys.iter().collect();
|
|
||||||
|
|
||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
|
|
||||||
let encrypted_msg = if let Some(ref skey) = private_key_for_signing {
|
let encrypted_msg = if let Some(ref skey) = private_key_for_signing {
|
||||||
let signed_msg = lit_msg.sign(skey, || "".into(), HASH_ALGORITHM)?;
|
let signed_msg = lit_msg.sign(skey, || "".into(), HASH_ALGORITHM)?;
|
||||||
let compressed_msg = if compress {
|
let compressed_msg = if compress {
|
||||||
signed_msg.compress(CompressionAlgorithm::ZLIB)?
|
signed_msg.compress(CompressionAlgorithm::ZLIB)?
|
||||||
} else {
|
|
||||||
signed_msg
|
|
||||||
};
|
|
||||||
compressed_msg.encrypt_to_keys(&mut rng, SYMMETRIC_KEY_ALGORITHM, &pkeys_refs)?
|
|
||||||
} else {
|
} else {
|
||||||
lit_msg.encrypt_to_keys(&mut rng, SYMMETRIC_KEY_ALGORITHM, &pkeys_refs)?
|
signed_msg
|
||||||
};
|
};
|
||||||
|
compressed_msg.encrypt_to_keys(&mut rng, SYMMETRIC_KEY_ALGORITHM, &pkeys_refs)?
|
||||||
|
} else {
|
||||||
|
lit_msg.encrypt_to_keys(&mut rng, SYMMETRIC_KEY_ALGORITHM, &pkeys_refs)?
|
||||||
|
};
|
||||||
|
|
||||||
let encoded_msg = encrypted_msg.to_armored_string(Default::default())?;
|
let encoded_msg = encrypted_msg.to_armored_string(Default::default())?;
|
||||||
|
|
||||||
Ok(encoded_msg)
|
Ok(encoded_msg)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Signs `plain` text using `private_key_for_signing`.
|
/// Signs `plain` text using `private_key_for_signing`.
|
||||||
|
|||||||
Reference in New Issue
Block a user