mirror of
https://github.com/chatmail/core.git
synced 2026-04-26 01:46:34 +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::parse_and_get_text,
|
||||
internals_for_benchmarks::store_self_keypair,
|
||||
pgp::{KeyPair, decrypt, encrypt_for_broadcast, pk_encrypt},
|
||||
pgp::{KeyPair, decrypt, encrypt_symmetrically, pk_encrypt},
|
||||
stock_str::StockStrings,
|
||||
};
|
||||
use rand::{Rng, thread_rng};
|
||||
@@ -83,7 +83,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|
||||
let secrets = generate_secrets();
|
||||
let encrypted = tokio::runtime::Runtime::new().unwrap().block_on(async {
|
||||
let secret = secrets[NUM_SECRETS / 2].clone();
|
||||
let encrypted = encrypt_for_broadcast(
|
||||
let encrypted = encrypt_symmetrically(
|
||||
plain.clone(),
|
||||
black_box(&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);
|
||||
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?;
|
||||
|
||||
Ok(ctext)
|
||||
}
|
||||
|
||||
/// TODO documentation
|
||||
pub async fn encrypt_for_broadcast(
|
||||
/// 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.
|
||||
pub async fn encrypt_symmetrically(
|
||||
self,
|
||||
context: &Context,
|
||||
passphrase: &str,
|
||||
shared_secret: &str,
|
||||
mail_to_encrypt: MimePart<'static>,
|
||||
compress: bool,
|
||||
) -> Result<String> {
|
||||
@@ -78,12 +75,8 @@ impl EncryptHelper {
|
||||
let cursor = Cursor::new(&mut raw_message);
|
||||
mail_to_encrypt.clone().write_part(cursor).ok();
|
||||
|
||||
println!(
|
||||
"\nEncrypting symm:\n{}\n",
|
||||
String::from_utf8_lossy(&raw_message)
|
||||
); // TODO
|
||||
|
||||
let ctext = pgp::encrypt_for_broadcast(raw_message, passphrase, sign_key, compress).await?;
|
||||
let ctext =
|
||||
pgp::encrypt_symmetrically(raw_message, shared_secret, sign_key, compress).await?;
|
||||
|
||||
Ok(ctext)
|
||||
}
|
||||
|
||||
@@ -1204,7 +1204,7 @@ impl MimeFactory {
|
||||
let encrypted = if let Some(shared_secret) = shared_secret {
|
||||
info!(context, "Encrypting symmetrically.");
|
||||
encrypt_helper
|
||||
.encrypt_for_broadcast(context, &shared_secret, message, compress)
|
||||
.encrypt_symmetrically(context, &shared_secret, message, compress)
|
||||
.await?
|
||||
} else {
|
||||
// Asymmetric encryption
|
||||
|
||||
@@ -336,9 +336,10 @@ pub async fn symm_encrypt(passphrase: &str, plain: Vec<u8>) -> Result<String> {
|
||||
.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.
|
||||
pub async fn encrypt_for_broadcast(
|
||||
pub async fn encrypt_symmetrically(
|
||||
plain: Vec<u8>,
|
||||
shared_secret: &str,
|
||||
private_key_for_signing: SignedSecretKey,
|
||||
@@ -607,7 +608,7 @@ mod tests {
|
||||
|
||||
let plain = Vec::from(b"this is the secret message");
|
||||
let shared_secret = "shared secret";
|
||||
let ctext = encrypt_for_broadcast(
|
||||
let ctext = encrypt_symmetrically(
|
||||
plain.clone(),
|
||||
shared_secret,
|
||||
load_self_secret_key(alice).await?,
|
||||
|
||||
Reference in New Issue
Block a user