mirror of
https://github.com/chatmail/core.git
synced 2026-05-16 21:36:30 +03:00
resolve some small TODOs
This commit is contained in:
@@ -38,7 +38,7 @@ use deltachat::{
|
|||||||
internals_for_benchmarks::key_from_asc,
|
internals_for_benchmarks::key_from_asc,
|
||||||
internals_for_benchmarks::parse_and_get_text,
|
internals_for_benchmarks::parse_and_get_text,
|
||||||
internals_for_benchmarks::store_self_keypair,
|
internals_for_benchmarks::store_self_keypair,
|
||||||
pgp::{KeyPair, decrypt, encrypt_for_broadcast, pk_encrypt},
|
pgp::{KeyPair, decrypt, encrypt_symmetrically, pk_encrypt},
|
||||||
stock_str::StockStrings,
|
stock_str::StockStrings,
|
||||||
};
|
};
|
||||||
use rand::{Rng, thread_rng};
|
use rand::{Rng, thread_rng};
|
||||||
@@ -83,7 +83,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|
|||||||
let secrets = generate_secrets();
|
let secrets = generate_secrets();
|
||||||
let encrypted = tokio::runtime::Runtime::new().unwrap().block_on(async {
|
let encrypted = tokio::runtime::Runtime::new().unwrap().block_on(async {
|
||||||
let secret = secrets[NUM_SECRETS / 2].clone();
|
let secret = secrets[NUM_SECRETS / 2].clone();
|
||||||
let encrypted = encrypt_for_broadcast(
|
let encrypted = encrypt_symmetrically(
|
||||||
plain.clone(),
|
plain.clone(),
|
||||||
black_box(&secret),
|
black_box(&secret),
|
||||||
create_dummy_keypair("alice@example.org").unwrap().secret,
|
create_dummy_keypair("alice@example.org").unwrap().secret,
|
||||||
|
|||||||
21
src/e2ee.rs
21
src/e2ee.rs
@@ -54,21 +54,18 @@ impl EncryptHelper {
|
|||||||
let cursor = Cursor::new(&mut raw_message);
|
let cursor = Cursor::new(&mut raw_message);
|
||||||
mail_to_encrypt.clone().write_part(cursor).ok();
|
mail_to_encrypt.clone().write_part(cursor).ok();
|
||||||
|
|
||||||
println!(
|
|
||||||
"\nEncrypting pk:\n{}\n",
|
|
||||||
String::from_utf8_lossy(&raw_message)
|
|
||||||
); // TODO
|
|
||||||
|
|
||||||
let ctext = pgp::pk_encrypt(raw_message, keyring, Some(sign_key), compress).await?;
|
let ctext = pgp::pk_encrypt(raw_message, keyring, Some(sign_key), compress).await?;
|
||||||
|
|
||||||
Ok(ctext)
|
Ok(ctext)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO documentation
|
/// Symmetrically encrypt the message to be sent into a broadcast channel,
|
||||||
pub async fn encrypt_for_broadcast(
|
/// or for version 2 of the Securejoin protocol.
|
||||||
|
/// `shared secret` is the secret that will be used for symmetric encryption.
|
||||||
|
pub async fn encrypt_symmetrically(
|
||||||
self,
|
self,
|
||||||
context: &Context,
|
context: &Context,
|
||||||
passphrase: &str,
|
shared_secret: &str,
|
||||||
mail_to_encrypt: MimePart<'static>,
|
mail_to_encrypt: MimePart<'static>,
|
||||||
compress: bool,
|
compress: bool,
|
||||||
) -> Result<String> {
|
) -> Result<String> {
|
||||||
@@ -78,12 +75,8 @@ impl EncryptHelper {
|
|||||||
let cursor = Cursor::new(&mut raw_message);
|
let cursor = Cursor::new(&mut raw_message);
|
||||||
mail_to_encrypt.clone().write_part(cursor).ok();
|
mail_to_encrypt.clone().write_part(cursor).ok();
|
||||||
|
|
||||||
println!(
|
let ctext =
|
||||||
"\nEncrypting symm:\n{}\n",
|
pgp::encrypt_symmetrically(raw_message, shared_secret, sign_key, compress).await?;
|
||||||
String::from_utf8_lossy(&raw_message)
|
|
||||||
); // TODO
|
|
||||||
|
|
||||||
let ctext = pgp::encrypt_for_broadcast(raw_message, passphrase, sign_key, compress).await?;
|
|
||||||
|
|
||||||
Ok(ctext)
|
Ok(ctext)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1204,7 +1204,7 @@ impl MimeFactory {
|
|||||||
let encrypted = if let Some(shared_secret) = shared_secret {
|
let encrypted = if let Some(shared_secret) = shared_secret {
|
||||||
info!(context, "Encrypting symmetrically.");
|
info!(context, "Encrypting symmetrically.");
|
||||||
encrypt_helper
|
encrypt_helper
|
||||||
.encrypt_for_broadcast(context, &shared_secret, message, compress)
|
.encrypt_symmetrically(context, &shared_secret, message, compress)
|
||||||
.await?
|
.await?
|
||||||
} else {
|
} else {
|
||||||
// Asymmetric encryption
|
// Asymmetric encryption
|
||||||
|
|||||||
@@ -336,9 +336,10 @@ pub async fn symm_encrypt(passphrase: &str, plain: Vec<u8>) -> Result<String> {
|
|||||||
.await?
|
.await?
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Symmetrically encrypt the message to be sent into a broadcast channel.
|
/// Symmetrically encrypt the message to be sent into a broadcast channel,
|
||||||
|
/// or for version 2 of the Securejoin protocol.
|
||||||
/// `shared secret` is the secret that will be used for symmetric encryption.
|
/// `shared secret` is the secret that will be used for symmetric encryption.
|
||||||
pub async fn encrypt_for_broadcast(
|
pub async fn encrypt_symmetrically(
|
||||||
plain: Vec<u8>,
|
plain: Vec<u8>,
|
||||||
shared_secret: &str,
|
shared_secret: &str,
|
||||||
private_key_for_signing: SignedSecretKey,
|
private_key_for_signing: SignedSecretKey,
|
||||||
@@ -607,7 +608,7 @@ mod tests {
|
|||||||
|
|
||||||
let plain = Vec::from(b"this is the secret message");
|
let plain = Vec::from(b"this is the secret message");
|
||||||
let shared_secret = "shared secret";
|
let shared_secret = "shared secret";
|
||||||
let ctext = encrypt_for_broadcast(
|
let ctext = encrypt_symmetrically(
|
||||||
plain.clone(),
|
plain.clone(),
|
||||||
shared_secret,
|
shared_secret,
|
||||||
load_self_secret_key(alice).await?,
|
load_self_secret_key(alice).await?,
|
||||||
|
|||||||
Reference in New Issue
Block a user