summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2019-05-07 12:11:31 +0200
committerNeal H. Walfield <neal@pep.foundation>2019-05-07 12:18:46 +0200
commita23be8beccfb4bec44ea99ce6943b50800998b01 (patch)
tree55fe18b599ebf150ac4e995b56d61ed8285370e9
parentbc74fdabb41c6957de6d6adfaea5fe1858fce3ea (diff)
openpgp: Add a method to TPKBuilder to create a general-purpose key
- Add a convenience method to TPKBuilder to create a typical, general-purpose key, i.e., one with a certification- and signing-capable primary key, and an encryption-capable subkey.
-rw-r--r--openpgp/src/tpk/builder.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/openpgp/src/tpk/builder.rs b/openpgp/src/tpk/builder.rs
index 11d4790c..dc1a55e5 100644
--- a/openpgp/src/tpk/builder.rs
+++ b/openpgp/src/tpk/builder.rs
@@ -123,6 +123,34 @@ impl TPKBuilder {
}
}
+ /// Generates a general-purpose key.
+ ///
+ /// The key's primary key is certification- and signature-capable.
+ /// The key has one subkey, an encryption-capable subkey.
+ pub fn general_purpose<C, U>(ciphersuite: C, userids: Option<U>) -> Self
+ where C: Into<Option<CipherSuite>>,
+ U: Into<packet::UserID>
+ {
+ TPKBuilder {
+ ciphersuite: ciphersuite.into().unwrap_or(Default::default()),
+ primary: KeyBlueprint{
+ flags: KeyFlags::default()
+ .set_certify(true)
+ .set_sign(true)
+ },
+ subkeys: vec![
+ KeyBlueprint{
+ flags: KeyFlags::default()
+ .set_encrypt_for_transport(true)
+ .set_encrypt_at_rest(true)
+ }
+ ],
+ userids: userids.into_iter().map(|x| x.into()).collect(),
+ user_attributes: vec![],
+ password: None,
+ }
+ }
+
/// Generates a key compliant to
/// [Autocrypt](https://autocrypt.org/).
///