From 4cb6e347e8436a86b62fa32f8cd11caef9767692 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Wed, 28 Apr 2021 12:58:24 +0200 Subject: openpgp: Simplify constructor. --- openpgp/src/cert/builder.rs | 42 +++++++++++++----------------------------- 1 file changed, 13 insertions(+), 29 deletions(-) (limited to 'openpgp/src/cert') diff --git a/openpgp/src/cert/builder.rs b/openpgp/src/cert/builder.rs index 05c3859e..3d142c48 100644 --- a/openpgp/src/cert/builder.rs +++ b/openpgp/src/cert/builder.rs @@ -254,40 +254,24 @@ impl CertBuilder<'_> { /// # Ok(()) /// # } /// ``` - pub fn general_purpose(ciphersuite: C, userids: Option) -> Self + pub fn general_purpose(ciphersuite: C, userid: Option) -> Self where C: Into>, U: Into { - CertBuilder { - creation_time: None, - ciphersuite: ciphersuite.into().unwrap_or_default(), - primary: KeyBlueprint { - flags: KeyFlags::empty() - .set_certification(), - validity: Some(time::Duration::new(3 * 52 * 7 * 24 * 60 * 60, 0)), - ciphersuite: None, - }, - subkeys: vec![ - KeyBlueprint { - flags: KeyFlags::empty() - .set_signing(), - validity: None, - ciphersuite: None, - }, - KeyBlueprint { - flags: KeyFlags::empty() + let mut builder = Self::new() + .set_cipher_suite(ciphersuite.into().unwrap_or_default()) + .set_primary_key_flags(KeyFlags::empty().set_certification()) + .set_validity_period( + time::Duration::new(3 * 52 * 7 * 24 * 60 * 60, 0)) + .add_signing_subkey() + .add_subkey(KeyFlags::empty() .set_transport_encryption() - .set_storage_encryption(), - validity: None, - ciphersuite: None, - } - ], - userids: userids.into_iter().map(|x| x.into()).collect(), - user_attributes: vec![], - password: None, - revocation_keys: None, - phantom: PhantomData, + .set_storage_encryption(), None, None); + if let Some(u) = userid.map(Into::into) { + builder = builder.add_userid(u); } + + builder } /// Sets the creation time. -- cgit v1.2.3