File: encrypt_sign_message.rs

package info (click to toggle)
rust-sequoia-openpgp 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 9,372 kB
  • sloc: sh: 6; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 1,071 bytes parent folder | download
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
use criterion::{criterion_group, BenchmarkId, Criterion, Throughput};

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

use crate::common::encrypt;

pub fn encrypt_to_donald_sign_by_ivanka(bytes: &[u8]) {
    let sender = Cert::from_bytes(
        &include_bytes!("../tests/data/keys/ivanka-private.gpg")[..],
    )
    .unwrap();
    let recipient = Cert::from_bytes(
        &include_bytes!("../tests/data/keys/the-donald-private.gpg")[..],
    )
    .unwrap();
    encrypt::encrypt_to_cert_and_sign(bytes, &sender, &recipient).unwrap();
}

fn bench_encrypt_sign(c: &mut Criterion) {
    let mut group = c.benchmark_group("encrypt and sign message");

    for message in encrypt::messages() {
        group.throughput(Throughput::Bytes(message.len() as u64));
        group.bench_with_input(
            BenchmarkId::new("encrypt and sign", message.len()),
            &message,
            |b, m| b.iter(|| encrypt_to_donald_sign_by_ivanka(m)),
        );
    }
    group.finish();
}

criterion_group!(benches, bench_encrypt_sign);