summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNora Widdecke <nora@sequoia-pgp.org>2021-01-19 16:54:05 +0100
committerNora Widdecke <nora@sequoia-pgp.org>2021-01-19 16:54:05 +0100
commite956fa7f69517d70292a2260e8f6986012a4447b (patch)
treee4613dcc2e679f17f173284775ddd56617af5bd4
parent8e87428b8debda2de6f18d3969668ecbbcda1e76 (diff)
add encrypting to recipient.
-rw-r--r--openpgp/benches/encrypt_message.rs44
1 files changed, 42 insertions, 2 deletions
diff --git a/openpgp/benches/encrypt_message.rs b/openpgp/benches/encrypt_message.rs
index a81c9f31..13aef2bf 100644
--- a/openpgp/benches/encrypt_message.rs
+++ b/openpgp/benches/encrypt_message.rs
@@ -1,6 +1,10 @@
use criterion::{criterion_group, criterion_main, Criterion};
+use sequoia_openpgp::cert::Cert;
+use sequoia_openpgp::parse::Parse;
use sequoia_openpgp::serialize::stream::{Encryptor, LiteralWriter, Message};
+use sequoia_openpgp::policy::StandardPolicy;
+
use std::io::Write;
lazy_static::lazy_static! {
@@ -8,6 +12,27 @@ lazy_static::lazy_static! {
static ref ZEROS_10_MB: Vec<u8> = vec![0; 10 * 1024 * 1024];
}
+
+fn encrypt_to_testy(bytes: &[u8]) -> sequoia_openpgp::Result<()> {
+ let mut sink = vec![];
+ let testy =
+ Cert::from_bytes(&include_bytes!("../tests/data/keys/testy.pgp")[..])?;
+ let p = &StandardPolicy::new();
+ let recipients = testy
+ .keys()
+ .with_policy(p, None)
+ .supported()
+ .alive()
+ .revoked(false)
+ .for_transport_encryption();
+ let message =
+ Encryptor::for_recipients(Message::new(&mut sink), recipients).build()?;
+ let mut w = LiteralWriter::new(message).build()?;
+ w.write_all(bytes)?;
+ w.finalize()?;
+ Ok(())
+}
+
fn encrypt_with_password(bytes: &[u8]) -> sequoia_openpgp::Result<()> {
let mut sink = vec![];
let message = Encryptor::with_passwords(
@@ -21,23 +46,38 @@ fn encrypt_with_password(bytes: &[u8]) -> sequoia_openpgp::Result<()> {
Ok(())
}
-fn bench_encrypt_with_password(c: &mut Criterion) {
+fn bench_encrypt(c: &mut Criterion) {
let mut group = c.benchmark_group("encrypt message");
+
+ // Encrypt a very short message.
let bytes = b"Hello world.";
group.bench_function(format!("password {:?}", bytes.len()), |b| {
b.iter(|| encrypt_with_password(bytes))
});
+ group.bench_function(format!("recipient {:?}", bytes.len()), |b| {
+ b.iter(|| encrypt_to_testy(bytes))
+ });
+
+ // Encrypt a medium length message.
let bytes = &ZEROS_1_MB[..];
group.bench_function(format!("password {:?}", bytes.len()), |b| {
b.iter(|| encrypt_with_password(bytes))
});
+ group.bench_function(format!("recipient {:?}", bytes.len()), |b| {
+ b.iter(|| encrypt_to_testy(bytes))
+ });
+
+ // Encrypt a very long message.
let bytes = &ZEROS_10_MB[..];
group.bench_function(format!("password {:?}", bytes.len()), |b| {
b.iter(|| encrypt_with_password(bytes))
});
+ group.bench_function(format!("recipient {:?}", bytes.len()), |b| {
+ b.iter(|| encrypt_to_testy(bytes))
+ });
group.finish();
}
-criterion_group!(benches, bench_encrypt_with_password);
+criterion_group!(benches, bench_encrypt);
criterion_main!(benches);