More deduplication.

parent 1d06b06a
......@@ -150,32 +150,6 @@ impl ConsumerTest for BindingSignatureSubpackets {
), true)?;
fn make_test(test: &str, packets: Vec<openpgp::Packet>,
expectation: Option<Expectation>)
-> Result<(String, Data, Option<Expectation>)> {
use openpgp::Packet;
use openpgp::serialize::Serialize;
let has_secrets = packets.iter().any(|p| match p {
Packet::SecretKey(_) | Packet::SecretSubkey(_) => true,
_ => false,
});
let mut buf = Vec::new();
{
let mut w =
armor::Writer::new(&mut buf,
if has_secrets {
armor::Kind::SecretKey
} else {
armor::Kind::PublicKey
})?;
openpgp::PacketPile::from(packets).serialize(&mut w)?;
w.finalize()?;
}
Ok((test.into(), buf.into(), expectation))
}
let primary_fp = cert.fingerprint();
let primary_id = cert.keyid();
......@@ -198,6 +172,9 @@ impl ConsumerTest for BindingSignatureSubpackets {
},
false)?;
let make_test = |test, packets: Vec<openpgp::Packet>, expectation| {
super::make_test(test, packets, expectation)
};
Ok(vec![
make_test("Base case", vec![
primary.clone().into(),
......
......@@ -165,36 +165,13 @@ impl ConsumerTest for DetachedPrimary {
.parts_as_secret()?.clone();
let mut subkey_signer = subkey.clone().into_keypair().unwrap();
fn make_test(test: &str, packets: Vec<openpgp::Packet>,
expectation: Option<Expectation>)
-> Result<(String, Data, Option<Expectation>)> {
use openpgp::Packet;
use openpgp::serialize::Serialize;
let has_secrets = packets.iter().any(|p| match p {
Packet::SecretKey(_) | Packet::SecretSubkey(_) => true,
_ => false,
});
let mut buf = Vec::new();
{
let mut w =
armor::Writer::new(&mut buf,
if has_secrets {
armor::Kind::SecretKey
} else {
armor::Kind::PublicKey
})?;
openpgp::PacketPile::from(packets).serialize(&mut w)?;
w.finalize()?;
}
Ok((test.into(), buf.into(), expectation))
}
let backsig = SignatureBuilder::new(SignatureType::PrimaryKeyBinding)
.set_signature_creation_time(half_a_year_ago)?
.sign_primary_key_binding(&mut subkey_signer, &primary, &subkey)?;
let make_test = |test, packets: Vec<openpgp::Packet>, expectation| {
super::make_test(test, packets, expectation)
};
Ok(vec![
make_test("SecKey SecSubkey", vec![
primary.clone().into(),
......
......@@ -141,35 +141,12 @@ impl ConsumerTest for KeyFlagsComposition {
let mut subkey_signer =
subkey.clone().parts_into_secret()?.into_keypair().unwrap();
fn make_test(test: &str, packets: Vec<openpgp::Packet>,
expectation: Option<Expectation>)
-> Result<(String, Data, Option<Expectation>)> {
use openpgp::Packet;
use openpgp::serialize::Serialize;
let has_secrets = packets.iter().any(|p| match p {
Packet::SecretKey(_) | Packet::SecretSubkey(_) => true,
_ => false,
});
let mut buf = Vec::new();
{
let mut w =
armor::Writer::new(&mut buf,
if has_secrets {
armor::Kind::SecretKey
} else {
armor::Kind::PublicKey
})?;
openpgp::PacketPile::from(packets).serialize(&mut w)?;
w.finalize()?;
}
Ok((test.into(), buf.into(), expectation))
}
let backsig = SignatureBuilder::new(SignatureType::PrimaryKeyBinding)
.sign_primary_key_binding(&mut subkey_signer, &primary, &subkey)?;
let make_test = |test, packets: Vec<openpgp::Packet>, expectation| {
super::make_test(test, packets, expectation)
};
Ok(vec![
make_test("p u[C] s[S]", vec![
primary.clone().into(),
......
......@@ -128,32 +128,9 @@ impl ConsumerTest for PrimaryKeyBinding {
let mut subkey_signer =
subkey.clone().parts_into_secret()?.into_keypair().unwrap();
fn make_test(test: &str, packets: Vec<openpgp::Packet>,
expectation: Option<Expectation>)
-> Result<(String, Data, Option<Expectation>)> {
use openpgp::Packet;
use openpgp::serialize::Serialize;
let has_secrets = packets.iter().any(|p| match p {
Packet::SecretKey(_) | Packet::SecretSubkey(_) => true,
_ => false,
});
let mut buf = Vec::new();
{
let mut w =
armor::Writer::new(&mut buf,
if has_secrets {
armor::Kind::SecretKey
} else {
armor::Kind::PublicKey
})?;
openpgp::PacketPile::from(packets).serialize(&mut w)?;
w.finalize()?;
}
Ok((test.into(), buf.into(), expectation))
}
let make_test = |test, packets: Vec<openpgp::Packet>, expectation| {
super::make_test(test, packets, expectation)
};
Ok(vec![
make_test("Base case", vec![
primary.clone().into(),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment