Make helper function more generic.

- Change `compare_notations` from taking a slice containing two
    elements to taking a slice taking any number of elements.
This commit is contained in:
Neal H. Walfield 2024-06-12 14:12:57 +02:00
parent 9f09e34e36
commit 1817c305ae
No known key found for this signature in database
GPG Key ID: 6863C9AD5B4D22D3
4 changed files with 90 additions and 102 deletions

View File

@ -774,9 +774,9 @@ pub fn sq_key_generate(
/// Returns an error if a notation can not be found in the Signature /// Returns an error if a notation can not be found in the Signature
pub fn compare_notations( pub fn compare_notations(
signature: &Signature, signature: &Signature,
notations: Option<&[(&str, &str); 2]>, notations: &[(&str, &str)],
) -> Result<()> { ) -> Result<()> {
if let Some(notations) = notations { if ! notations.is_empty() {
let found_notations: Vec<(&str, String)> = signature let found_notations: Vec<(&str, String)> = signature
.notation_data() .notation_data()
.map(|n| (n.name(), String::from_utf8_lossy(n.value()).into())) .map(|n| (n.name(), String::from_utf8_lossy(n.value()).into()))

View File

@ -34,46 +34,46 @@ fn sq_key_revoke() -> Result<()> {
( (
ReasonForRevocation::KeyCompromised, ReasonForRevocation::KeyCompromised,
"compromised", "compromised",
None, &[][..],
None, None,
), ),
( (
ReasonForRevocation::KeyCompromised, ReasonForRevocation::KeyCompromised,
"compromised", "compromised",
None, &[][..],
Some(time + Duration::hours(1)), Some(time + Duration::hours(1)),
), ),
( (
ReasonForRevocation::KeyCompromised, ReasonForRevocation::KeyCompromised,
"compromised", "compromised",
Some(&[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")]), &[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")][..],
None, None,
), ),
(ReasonForRevocation::KeyRetired, "retired", None, None), (ReasonForRevocation::KeyRetired, "retired", &[][..], None),
( (
ReasonForRevocation::KeyRetired, ReasonForRevocation::KeyRetired,
"retired", "retired",
Some(&[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")]), &[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")][..],
None, None,
), ),
(ReasonForRevocation::KeySuperseded, "superseded", None, None), (ReasonForRevocation::KeySuperseded, "superseded", &[][..], None),
( (
ReasonForRevocation::KeySuperseded, ReasonForRevocation::KeySuperseded,
"superseded", "superseded",
Some(&[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")]), &[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")][..],
None, None,
), ),
(ReasonForRevocation::Unspecified, "unspecified", None, None), (ReasonForRevocation::Unspecified, "unspecified", &[][..], None),
( (
ReasonForRevocation::Unspecified, ReasonForRevocation::Unspecified,
"unspecified", "unspecified",
None, &[][..],
Some(time + Duration::hours(1)), Some(time + Duration::hours(1)),
), ),
( (
ReasonForRevocation::Unspecified, ReasonForRevocation::Unspecified,
"unspecified", "unspecified",
Some(&[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")]), &[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")][..],
None, None,
), ),
] { ] {
@ -91,10 +91,10 @@ fn sq_key_revoke() -> Result<()> {
let revocation = &tmpdir.path().join(format!( let revocation = &tmpdir.path().join(format!(
"revocation_{}_{}_{}.rev", "revocation_{}_{}_{}.rev",
reason_str, reason_str,
if notations.is_some() { if ! notations.is_empty() {
"notations"
} else {
"no_notations" "no_notations"
} else {
"notations"
}, },
if revocation_time.is_some() { if revocation_time.is_some() {
"time" "time"
@ -143,10 +143,8 @@ fn sq_key_revoke() -> Result<()> {
]); ]);
} }
if let Some(notations) = notations { for (k, v) in notations {
for (k, v) in notations { cmd.args(["--notation", k, v]);
cmd.args(["--notation", k, v]);
}
} }
if let Some(time) = revocation_time { if let Some(time) = revocation_time {
cmd.args([ cmd.args([
@ -255,58 +253,58 @@ fn sq_key_revoke_thirdparty() -> Result<()> {
( (
ReasonForRevocation::KeyCompromised, ReasonForRevocation::KeyCompromised,
"compromised", "compromised",
None, &[][..],
None, None,
), ),
( (
ReasonForRevocation::KeyCompromised, ReasonForRevocation::KeyCompromised,
"compromised", "compromised",
None, &[][..],
Some(thirdparty_time + Duration::hours(1)), Some(thirdparty_time + Duration::hours(1)),
), ),
( (
ReasonForRevocation::KeyCompromised, ReasonForRevocation::KeyCompromised,
"compromised", "compromised",
Some(&[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")]), &[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")][..],
None, None,
), ),
(ReasonForRevocation::KeyRetired, "retired", None, None), (ReasonForRevocation::KeyRetired, "retired", &[][..], None),
( (
ReasonForRevocation::KeyRetired, ReasonForRevocation::KeyRetired,
"retired", "retired",
None, &[][..],
Some(thirdparty_time + Duration::hours(1)), Some(thirdparty_time + Duration::hours(1)),
), ),
( (
ReasonForRevocation::KeyRetired, ReasonForRevocation::KeyRetired,
"retired", "retired",
Some(&[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")]), &[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")][..],
None, None,
), ),
(ReasonForRevocation::KeySuperseded, "superseded", None, None), (ReasonForRevocation::KeySuperseded, "superseded", &[][..], None),
( (
ReasonForRevocation::KeySuperseded, ReasonForRevocation::KeySuperseded,
"superseded", "superseded",
None, &[][..],
Some(thirdparty_time + Duration::hours(1)), Some(thirdparty_time + Duration::hours(1)),
), ),
( (
ReasonForRevocation::KeySuperseded, ReasonForRevocation::KeySuperseded,
"superseded", "superseded",
Some(&[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")]), &[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")][..],
None, None,
), ),
(ReasonForRevocation::Unspecified, "unspecified", None, None), (ReasonForRevocation::Unspecified, "unspecified", &[][..], None),
( (
ReasonForRevocation::Unspecified, ReasonForRevocation::Unspecified,
"unspecified", "unspecified",
None, &[][..],
Some(thirdparty_time + Duration::hours(1)), Some(thirdparty_time + Duration::hours(1)),
), ),
( (
ReasonForRevocation::Unspecified, ReasonForRevocation::Unspecified,
"unspecified", "unspecified",
Some(&[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")]), &[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")][..],
None, None,
), ),
] { ] {
@ -317,10 +315,10 @@ fn sq_key_revoke_thirdparty() -> Result<()> {
let revocation = &tmpdir.path().join(format!( let revocation = &tmpdir.path().join(format!(
"revocation_{}_{}_{}.rev", "revocation_{}_{}_{}.rev",
reason_str, reason_str,
if notations.is_some() { if ! notations.is_empty() {
"notations"
} else {
"no_notations" "no_notations"
} else {
"notations"
}, },
if revocation_time.is_some() { if revocation_time.is_some() {
"time" "time"
@ -375,10 +373,8 @@ fn sq_key_revoke_thirdparty() -> Result<()> {
]); ]);
} }
if let Some(notations) = notations { for (k, v) in notations {
for (k, v) in notations { cmd.args(["--notation", k, v]);
cmd.args(["--notation", k, v]);
}
} }
if let Some(time) = revocation_time { if let Some(time) = revocation_time {
cmd.args([ cmd.args([

View File

@ -141,58 +141,58 @@ fn sq_key_subkey_revoke() -> Result<()> {
( (
ReasonForRevocation::KeyCompromised, ReasonForRevocation::KeyCompromised,
"compromised", "compromised",
None, &[][..],
None, None,
), ),
( (
ReasonForRevocation::KeyCompromised, ReasonForRevocation::KeyCompromised,
"compromised", "compromised",
None, &[][..],
Some(time + Duration::hours(1)), Some(time + Duration::hours(1)),
), ),
( (
ReasonForRevocation::KeyCompromised, ReasonForRevocation::KeyCompromised,
"compromised", "compromised",
Some(&[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")]), &[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")][..],
None, None,
), ),
(ReasonForRevocation::KeyRetired, "retired", None, None), (ReasonForRevocation::KeyRetired, "retired", &[][..], None),
( (
ReasonForRevocation::KeyRetired, ReasonForRevocation::KeyRetired,
"retired", "retired",
None, &[][..],
Some(time + Duration::hours(1)), Some(time + Duration::hours(1)),
), ),
( (
ReasonForRevocation::KeyRetired, ReasonForRevocation::KeyRetired,
"retired", "retired",
Some(&[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")]), &[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")][..],
None, None,
), ),
(ReasonForRevocation::KeySuperseded, "superseded", None, None), (ReasonForRevocation::KeySuperseded, "superseded", &[][..], None),
( (
ReasonForRevocation::KeySuperseded, ReasonForRevocation::KeySuperseded,
"superseded", "superseded",
None, &[][..],
Some(time + Duration::hours(1)), Some(time + Duration::hours(1)),
), ),
( (
ReasonForRevocation::KeySuperseded, ReasonForRevocation::KeySuperseded,
"superseded", "superseded",
Some(&[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")]), &[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")][..],
None, None,
), ),
(ReasonForRevocation::Unspecified, "unspecified", None, None), (ReasonForRevocation::Unspecified, "unspecified", &[][..], None),
( (
ReasonForRevocation::Unspecified, ReasonForRevocation::Unspecified,
"unspecified", "unspecified",
None, &[][..],
Some(time + Duration::hours(1)), Some(time + Duration::hours(1)),
), ),
( (
ReasonForRevocation::Unspecified, ReasonForRevocation::Unspecified,
"unspecified", "unspecified",
Some(&[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")]), &[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")][..],
None, None,
), ),
] { ] {
@ -210,10 +210,10 @@ fn sq_key_subkey_revoke() -> Result<()> {
let revocation = &tmpdir.path().join(format!( let revocation = &tmpdir.path().join(format!(
"revocation_{}_{}_{}.rev", "revocation_{}_{}_{}.rev",
reason_str, reason_str,
if notations.is_some() { if notations.is_empty() {
"notations"
} else {
"no_notations" "no_notations"
} else {
"notations"
}, },
if revocation_time.is_some() { if revocation_time.is_some() {
"time" "time"
@ -264,10 +264,8 @@ fn sq_key_subkey_revoke() -> Result<()> {
]); ]);
} }
if let Some(notations) = notations { for (k, v) in notations {
for (k, v) in notations { cmd.args(["--notation", k, v]);
cmd.args(["--notation", k, v]);
}
} }
if let Some(time) = revocation_time { if let Some(time) = revocation_time {
cmd.args([ cmd.args([
@ -404,58 +402,58 @@ fn sq_key_subkey_revoke_thirdparty() -> Result<()> {
( (
ReasonForRevocation::KeyCompromised, ReasonForRevocation::KeyCompromised,
"compromised", "compromised",
None, &[][..],
None, None,
), ),
( (
ReasonForRevocation::KeyCompromised, ReasonForRevocation::KeyCompromised,
"compromised", "compromised",
None, &[][..],
Some(thirdparty_time + Duration::hours(1)), Some(thirdparty_time + Duration::hours(1)),
), ),
( (
ReasonForRevocation::KeyCompromised, ReasonForRevocation::KeyCompromised,
"compromised", "compromised",
Some(&[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")]), &[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")][..],
None, None,
), ),
(ReasonForRevocation::KeyRetired, "retired", None, None), (ReasonForRevocation::KeyRetired, "retired", &[][..], None),
( (
ReasonForRevocation::KeyRetired, ReasonForRevocation::KeyRetired,
"retired", "retired",
None, &[][..],
Some(thirdparty_time + Duration::hours(1)), Some(thirdparty_time + Duration::hours(1)),
), ),
( (
ReasonForRevocation::KeyRetired, ReasonForRevocation::KeyRetired,
"retired", "retired",
Some(&[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")]), &[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")][..],
None, None,
), ),
(ReasonForRevocation::KeySuperseded, "superseded", None, None), (ReasonForRevocation::KeySuperseded, "superseded", &[][..], None),
( (
ReasonForRevocation::KeySuperseded, ReasonForRevocation::KeySuperseded,
"superseded", "superseded",
None, &[][..],
Some(thirdparty_time + Duration::hours(1)), Some(thirdparty_time + Duration::hours(1)),
), ),
( (
ReasonForRevocation::KeySuperseded, ReasonForRevocation::KeySuperseded,
"superseded", "superseded",
Some(&[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")]), &[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")][..],
None, None,
), ),
(ReasonForRevocation::Unspecified, "unspecified", None, None), (ReasonForRevocation::Unspecified, "unspecified", &[][..], None),
( (
ReasonForRevocation::Unspecified, ReasonForRevocation::Unspecified,
"unspecified", "unspecified",
None, &[][..],
Some(thirdparty_time + Duration::hours(1)), Some(thirdparty_time + Duration::hours(1)),
), ),
( (
ReasonForRevocation::Unspecified, ReasonForRevocation::Unspecified,
"unspecified", "unspecified",
Some(&[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")]), &[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")][..],
None, None,
), ),
] { ] {
@ -466,10 +464,10 @@ fn sq_key_subkey_revoke_thirdparty() -> Result<()> {
let revocation = &tmpdir.path().join(format!( let revocation = &tmpdir.path().join(format!(
"revocation_{}_{}_{}.rev", "revocation_{}_{}_{}.rev",
reason_str, reason_str,
if notations.is_some() { if ! notations.is_empty() {
"notations"
} else {
"no_notations" "no_notations"
} else {
"notations"
}, },
if revocation_time.is_some() { if revocation_time.is_some() {
"time" "time"
@ -526,10 +524,8 @@ fn sq_key_subkey_revoke_thirdparty() -> Result<()> {
]); ]);
} }
if let Some(notations) = notations { for (k, v) in notations {
for (k, v) in notations { cmd.args(["--notation", k, v]);
cmd.args(["--notation", k, v]);
}
} }
if let Some(time) = revocation_time { if let Some(time) = revocation_time {
cmd.args([ cmd.args([

View File

@ -36,30 +36,30 @@ fn sq_key_userid_revoke() -> Result<()> {
// a revocation whose reference time is one hour after the creation of the // a revocation whose reference time is one hour after the creation of the
// certificate // certificate
for (reason, reason_str, notations, revocation_time) in [ for (reason, reason_str, notations, revocation_time) in [
(ReasonForRevocation::UIDRetired, "retired", None, None), (ReasonForRevocation::UIDRetired, "retired", &[][..], None),
( (
ReasonForRevocation::UIDRetired, ReasonForRevocation::UIDRetired,
"retired", "retired",
None, &[][..],
Some(time + Duration::hours(1)), Some(time + Duration::hours(1)),
), ),
( (
ReasonForRevocation::UIDRetired, ReasonForRevocation::UIDRetired,
"retired", "retired",
Some(&[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")]), &[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")][..],
None, None,
), ),
(ReasonForRevocation::Unspecified, "unspecified", None, None), (ReasonForRevocation::Unspecified, "unspecified", &[][..], None),
( (
ReasonForRevocation::Unspecified, ReasonForRevocation::Unspecified,
"unspecified", "unspecified",
None, &[][..],
Some(time + Duration::hours(1)), Some(time + Duration::hours(1)),
), ),
( (
ReasonForRevocation::Unspecified, ReasonForRevocation::Unspecified,
"unspecified", "unspecified",
Some(&[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")]), &[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")][..],
None, None,
), ),
] { ] {
@ -77,10 +77,10 @@ fn sq_key_userid_revoke() -> Result<()> {
let revocation = &tmpdir.path().join(format!( let revocation = &tmpdir.path().join(format!(
"revocation_{}_{}_{}.rev", "revocation_{}_{}_{}.rev",
reason_str, reason_str,
if notations.is_some() { if notations.is_empty() {
"notations"
} else {
"no_notations" "no_notations"
} else {
"notations"
}, },
if revocation_time.is_some() { if revocation_time.is_some() {
"time" "time"
@ -130,10 +130,8 @@ fn sq_key_userid_revoke() -> Result<()> {
]); ]);
} }
if let Some(notations) = notations { for (k, v) in notations {
for (k, v) in notations { cmd.args(["--notation", k, v]);
cmd.args(["--notation", k, v]);
}
} }
if let Some(time) = revocation_time { if let Some(time) = revocation_time {
cmd.args([ cmd.args([
@ -253,30 +251,30 @@ fn sq_key_userid_revoke_thirdparty() -> Result<()> {
// a revocation whose reference time is one hour after the creation of the // a revocation whose reference time is one hour after the creation of the
// certificate // certificate
for (reason, reason_str, notations, revocation_time) in [ for (reason, reason_str, notations, revocation_time) in [
(ReasonForRevocation::UIDRetired, "retired", None, None), (ReasonForRevocation::UIDRetired, "retired", &[][..], None),
( (
ReasonForRevocation::UIDRetired, ReasonForRevocation::UIDRetired,
"retired", "retired",
None, &[][..],
Some(thirdparty_time + Duration::hours(1)), Some(thirdparty_time + Duration::hours(1)),
), ),
( (
ReasonForRevocation::UIDRetired, ReasonForRevocation::UIDRetired,
"retired", "retired",
Some(&[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")]), &[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")][..],
None, None,
), ),
(ReasonForRevocation::Unspecified, "unspecified", None, None), (ReasonForRevocation::Unspecified, "unspecified", &[][..], None),
( (
ReasonForRevocation::Unspecified, ReasonForRevocation::Unspecified,
"unspecified", "unspecified",
None, &[][..],
Some(thirdparty_time + Duration::hours(1)), Some(thirdparty_time + Duration::hours(1)),
), ),
( (
ReasonForRevocation::Unspecified, ReasonForRevocation::Unspecified,
"unspecified", "unspecified",
Some(&[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")]), &[("foo", "bar"), ("hallo@sequoia-pgp.org", "VALUE")][..],
None, None,
), ),
] { ] {
@ -287,10 +285,10 @@ fn sq_key_userid_revoke_thirdparty() -> Result<()> {
let revocation = &tmpdir.path().join(format!( let revocation = &tmpdir.path().join(format!(
"revocation_{}_{}_{}.rev", "revocation_{}_{}_{}.rev",
reason_str, reason_str,
if notations.is_some() { if notations.is_empty() {
"notations"
} else {
"no_notations" "no_notations"
} else {
"notations"
}, },
if revocation_time.is_some() { if revocation_time.is_some() {
"time" "time"
@ -347,10 +345,8 @@ fn sq_key_userid_revoke_thirdparty() -> Result<()> {
]); ]);
} }
if let Some(notations) = notations { for (k, v) in notations {
for (k, v) in notations { cmd.args(["--notation", k, v]);
cmd.args(["--notation", k, v]);
}
} }
if let Some(time) = revocation_time { if let Some(time) = revocation_time {
cmd.args([ cmd.args([