File: decrypt_verify_message.rs

package info (click to toggle)
rust-sequoia-openpgp 2.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 9,548 kB
  • sloc: sh: 6; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,240 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use criterion::{
    criterion_group, criterion_main, BenchmarkId, Criterion, Throughput,
};

use sequoia_openpgp as openpgp;
use openpgp::cert::Cert;

use crate::common::{decrypt, encrypt};

fn decrypt_and_verify(bytes: &[u8], sender: &Cert, recipient: &Cert) {
    let mut sink = Vec::new();
    decrypt::decrypt_and_verify(&mut sink, bytes, sender, recipient).unwrap();
}

fn bench_decrypt_verify(c: &mut Criterion) {
    let mut group = c.benchmark_group("decrypt and verify message");

    encrypt::messages().for_each(|m| {
        let encrypted =
            encrypt::encrypt_to_cert_and_sign(m,
                                              encrypt::sender(),
                                              encrypt::recipient()).unwrap();
        group.throughput(Throughput::Bytes(encrypted.len() as u64));
        group.bench_with_input(
            BenchmarkId::new("decrypt and verify", m.len()),
            &encrypted,
            |b, e| b.iter(|| decrypt_and_verify(e,
                                                encrypt::sender(),
                                                encrypt::recipient())),
        );
    });

    group.finish();
}

criterion_group!(benches, bench_decrypt_verify);
criterion_main!(benches);