summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2020-03-01 13:25:16 +0100
committerNeal H. Walfield <neal@pep.foundation>2020-03-01 13:25:16 +0100
commit91b6d82a45b7ef61b26743788f77180af74c4871 (patch)
tree7204bdec6b57856f27be39437586d4b2eb46bcaf
parentf0c948c2f8227a0ee89a40e09d4a1dea2b06b218 (diff)
openpgp: Change KeyIter::subkeys' return type.
- Change `KeyIter::subkeys` to return a `SubordinateKeyAmalgamation` instead of a `KeyBundle`. - Remove `KeyIter::skip_primary`. It does the samething as `KeyIter::subkeys`, but `KeyIter::subkeys` has a more accurate type.
-rw-r--r--openpgp/src/cert/keyiter.rs40
-rw-r--r--openpgp/src/cert/mod.rs12
-rw-r--r--tool/src/commands/inspect.rs4
3 files changed, 22 insertions, 34 deletions
diff --git a/openpgp/src/cert/keyiter.rs b/openpgp/src/cert/keyiter.rs
index 744fb2cc..b8ebb5a3 100644
--- a/openpgp/src/cert/keyiter.rs
+++ b/openpgp/src/cert/keyiter.rs
@@ -262,9 +262,20 @@ impl<'a, P, R> KeyIter<'a, P, R>
}
/// Changes the iterator to skip the primary key.
- pub fn skip_primary(mut self) -> Self {
- self.primary = true;
- self
+ pub fn subkeys(self) -> KeyIter<'a, P, key::SubordinateRole> {
+ KeyIter {
+ cert: self.cert,
+ primary: true,
+ subkey_iter: self.subkey_iter,
+
+ // The filters.
+ secret: self.secret,
+ unencrypted_secret: self.unencrypted_secret,
+ key_handles: self.key_handles,
+
+ _p: std::marker::PhantomData,
+ _r: std::marker::PhantomData,
+ }
}
/// Changes the iterator to only return keys that are valid at
@@ -444,29 +455,6 @@ impl<'a, P, R> KeyIter<'a, P, R>
_r: std::marker::PhantomData,
}
}
-
- /// Changes the iterator to return subkey bundles.
- ///
- /// A key bundle is similar to a key amalgamation, but is not
- /// bound to a specific time. It contains the key and all
- /// relevant signatures.
- ///
- /// The primary key is never returned from this iterator.
- pub fn subkeys(self) -> KeyBundleIter<'a, P, key::SubordinateRole> {
- KeyBundleIter {
- cert: self.cert,
- primary: true,
- subkey_iter: self.subkey_iter,
-
- // The filters.
- secret: self.secret,
- unencrypted_secret: self.unencrypted_secret,
- key_handles: self.key_handles,
-
- _p: std::marker::PhantomData,
- _r: std::marker::PhantomData,
- }
- }
}
/// An iterator over all valid `Key`s in a certificate.
diff --git a/openpgp/src/cert/mod.rs b/openpgp/src/cert/mod.rs
index 207d8594..be5078df 100644
--- a/openpgp/src/cert/mod.rs
+++ b/openpgp/src/cert/mod.rs
@@ -3265,8 +3265,8 @@ Pu1xwz57O4zo1VYf6TqHJzVC3OMvMUM2hhdecMUe5x6GorNaj6g=
key::Key4::generate_ecc(true, Curve::Ed25519)?.into();
let _signing_subkey_pair = signing_subkey.clone().into_keypair()?;
let cert = cert.merge_packets(vec![signing_subkey.into()])?;
- assert_eq!(cert.keys().skip_primary().count(), 1);
- assert_eq!(cert.keys().skip_primary().with_policy(&p, None).count(), 0);
+ assert_eq!(cert.keys().subkeys().count(), 1);
+ assert_eq!(cert.keys().subkeys().with_policy(&p, None).count(), 0);
// Add a component that Sequoia doesn't understand.
let mut fake_key = packet::Unknown::new(
@@ -3367,8 +3367,8 @@ Pu1xwz57O4zo1VYf6TqHJzVC3OMvMUM2hhdecMUe5x6GorNaj6g=
subkey_sec.clone().into(),
binding.clone().into(),
].into())?;
- assert_eq!(cert.keys().skip_primary().count(), 1);
- assert_eq!(cert.keys().unencrypted_secret().skip_primary().count(), 1);
+ assert_eq!(cert.keys().subkeys().count(), 1);
+ assert_eq!(cert.keys().unencrypted_secret().subkeys().count(), 1);
let cert = Cert::from_packet_pile(vec![
primary.clone().into(),
@@ -3377,8 +3377,8 @@ Pu1xwz57O4zo1VYf6TqHJzVC3OMvMUM2hhdecMUe5x6GorNaj6g=
subkey_pub.clone().into(),
binding.clone().into(),
].into())?;
- assert_eq!(cert.keys().skip_primary().count(), 1);
- assert_eq!(cert.keys().unencrypted_secret().skip_primary().count(), 1);
+ assert_eq!(cert.keys().subkeys().count(), 1);
+ assert_eq!(cert.keys().unencrypted_secret().subkeys().count(), 1);
Ok(())
}
diff --git a/tool/src/commands/inspect.rs b/tool/src/commands/inspect.rs
index 7684539c..56f97463 100644
--- a/tool/src/commands/inspect.rs
+++ b/tool/src/commands/inspect.rs
@@ -142,10 +142,10 @@ fn inspect_cert(policy: &dyn Policy,
print_keygrips, print_certifications)?;
writeln!(output)?;
- for vka in cert.keys().skip_primary().with_policy(policy, None) {
+ for vka in cert.keys().subkeys().with_policy(policy, None) {
writeln!(output, " Subkey: {}", vka.key().fingerprint())?;
inspect_revocation(output, "", vka.revoked())?;
- inspect_key(policy, output, "", vka.into(),
+ inspect_key(policy, output, "", vka.into_key_amalgamation().into(),
print_keygrips, print_certifications)?;
writeln!(output)?;
}