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
pub fn compare_notations(
signature: &Signature,
notations: Option<&[(&str, &str); 2]>,
notations: &[(&str, &str)],
) -> Result<()> {
if let Some(notations) = notations {
if ! notations.is_empty() {
let found_notations: Vec<(&str, String)> = signature
.notation_data()
.map(|n| (n.name(), String::from_utf8_lossy(n.value()).into()))

View File

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

View File

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