-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
use std::error::Error; | ||
use std::str::FromStr; | ||
|
||
use criterion::{self, criterion_group, criterion_main, Criterion}; | ||
|
||
use rpm::signature::pgp::{Signer, Verifier}; | ||
use rpm::{self, RPMPackage}; | ||
|
||
fn build_rpm(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("build_rpm"); | ||
|
||
group.bench_function("build_rpm", |b| { | ||
b.iter(|| { | ||
let pkg = | ||
rpm::RPMBuilder::new("test", "1.0.0", "MIT", "x86_64", "some awesome package") | ||
.compression(rpm::Compressor::from_str("gzip").unwrap()) | ||
.with_file( | ||
"./test_assets/awesome.toml", | ||
rpm::RPMFileOptions::new("/etc/awesome/config.toml").is_config(), | ||
) | ||
.unwrap() | ||
// file mode is inherited from source file | ||
.with_file( | ||
"./test_assets/awesome.py", | ||
rpm::RPMFileOptions::new("/usr/bin/awesome"), | ||
) | ||
.unwrap() | ||
.with_file( | ||
"./test_assets/awesome.toml", | ||
// you can set a custom mode and custom user too | ||
rpm::RPMFileOptions::new("/etc/awesome/second.toml") | ||
.mode(0o100744) | ||
.user("hugo"), | ||
) | ||
.unwrap() | ||
.pre_install_script("echo preinst") | ||
.add_changelog_entry("me", "was awesome, eh?", 123123123) | ||
.add_changelog_entry("you", "yeah, it was", 12312312) | ||
.requires(rpm::Dependency::any("wget")) | ||
.vendor("corporation or individual") | ||
.url("www.github.com/repo") | ||
.vcs("git:repo=example_repo:branch=example_branch:sha=example_sha") | ||
.build() | ||
.unwrap(); | ||
}) | ||
}); | ||
group.finish(); | ||
} | ||
|
||
fn parse_rpm(c: &mut Criterion) -> Result<(), Box<dyn Error>> { | ||
let mut group = c.benchmark_group("parse_rpm"); | ||
let rpm_file = std::fs::read("test_assets/389-ds-base-devel-1.3.8.4-15.el7.x86_64.rpm")?; | ||
|
||
group.bench_function("parse_rpm", |b| { | ||
b.iter(|| { | ||
RPMPackage::parse(&mut std::io::Cursor::new(&rpm_file)).unwrap(); | ||
}) | ||
}); | ||
group.finish(); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn verify_rpm(c: &mut Criterion) -> Result<(), Box<dyn Error>> { | ||
let mut group = c.benchmark_group("verify_rpm"); | ||
|
||
let raw_pub_key = std::fs::read("test_assets/public_key.asc")?; | ||
let pkg = rpm::RPMPackage::open("test_assets/ima_signed.rpm")?; | ||
let verifier = Verifier::load_from_asc_bytes(&raw_pub_key).unwrap(); | ||
|
||
pkg.verify_signature(&verifier).unwrap(); | ||
|
||
group.bench_function("verify_rpm", |b| { | ||
b.iter(|| pkg.verify_signature(&verifier).unwrap()); | ||
}); | ||
group.finish(); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn sign_rpm(c: &mut Criterion) -> Result<(), Box<dyn Error>> { | ||
let mut group = c.benchmark_group("sign_rpm"); | ||
|
||
let raw_secret_key = std::fs::read("./test_assets/secret_key.asc")?; | ||
group.bench_function("sign_rpm", |b| { | ||
let mut pkg = | ||
rpm::RPMPackage::open("test_assets/389-ds-base-devel-1.3.8.4-15.el7.x86_64.rpm") | ||
.unwrap(); | ||
|
||
b.iter(|| { | ||
criterion::black_box( | ||
pkg.sign(Signer::load_from_asc_bytes(&raw_secret_key).unwrap()) | ||
.unwrap(), | ||
); | ||
}) | ||
}); | ||
group.finish(); | ||
|
||
Ok(()) | ||
} | ||
|
||
criterion_group!(benches, build_rpm, parse_rpm, sign_rpm, verify_rpm); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters