summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-11-26 13:57:42 +0100
committerJustus Winter <justus@sequoia-pgp.org>2020-11-26 15:22:34 +0100
commit0a432bfb0f17048ef7e1bdf672cb0aa6e4cd5786 (patch)
tree8e8336bfd0d7a1e1dba6b31ff18fe54fb190a9e7
parent67ec527d0ee1e15745e163ed1c550b385f885265 (diff)
openpgp: Add a lifetime to CertBuilder.
- This will allow us to use the CertBuilder to change certificates with detached secret keys in the future. - Fixes #608.
-rw-r--r--autocrypt/src/cert.rs2
-rw-r--r--openpgp-ffi/src/cert.rs4
-rw-r--r--openpgp/src/cert/builder.rs8
3 files changed, 9 insertions, 5 deletions
diff --git a/autocrypt/src/cert.rs b/autocrypt/src/cert.rs
index 7bbe2545..997c341f 100644
--- a/autocrypt/src/cert.rs
+++ b/autocrypt/src/cert.rs
@@ -18,7 +18,7 @@ use super::{
/// because it can be useful to add the UserID later, it is
/// permitted to be none.
pub fn cert_builder<'a, V, U>(version: V, userid: Option<U>)
- -> CertBuilder
+ -> CertBuilder<'a>
where V: Into<Option<Autocrypt>>,
U: Into<packet::UserID>
{
diff --git a/openpgp-ffi/src/cert.rs b/openpgp-ffi/src/cert.rs
index 84fd520d..6eecd3d3 100644
--- a/openpgp-ffi/src/cert.rs
+++ b/openpgp-ffi/src/cert.rs
@@ -906,7 +906,7 @@ pub extern "C" fn pgp_cert_parser_free(parser: Option<&mut CertParserWrapper>)
/// pgp_cert_free (cert);
/// ```
#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
-pub extern "C" fn pgp_cert_builder_new() -> *mut CertBuilder {
+pub extern "C" fn pgp_cert_builder_new() -> *mut CertBuilder<'static> {
box_raw!(CertBuilder::new())
}
@@ -917,7 +917,7 @@ pub extern "C" fn pgp_cert_builder_new() -> *mut CertBuilder {
#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
pub extern "C" fn pgp_cert_builder_general_purpose(cs: c_int,
uid: *const c_char)
- -> *mut CertBuilder
+ -> *mut CertBuilder<'static>
{
let uid = if uid.is_null() {
None
diff --git a/openpgp/src/cert/builder.rs b/openpgp/src/cert/builder.rs
index 63ebddcd..413dce36 100644
--- a/openpgp/src/cert/builder.rs
+++ b/openpgp/src/cert/builder.rs
@@ -1,4 +1,5 @@
use std::time;
+use std::marker::PhantomData;
use crate::packet;
use crate::packet::{
@@ -160,7 +161,7 @@ pub struct KeyBlueprint {
/// # }
/// ```
#[derive(Clone, Debug)]
-pub struct CertBuilder {
+pub struct CertBuilder<'a> {
creation_time: Option<std::time::SystemTime>,
ciphersuite: CipherSuite,
primary: KeyBlueprint,
@@ -169,9 +170,10 @@ pub struct CertBuilder {
user_attributes: Vec<packet::UserAttribute>,
password: Option<Password>,
revocation_keys: Option<Vec<RevocationKey>>,
+ phantom: PhantomData<&'a ()>,
}
-impl CertBuilder {
+impl CertBuilder<'_> {
/// Returns a new `CertBuilder`.
///
/// The returned builder is configured to generate a minimal
@@ -220,6 +222,7 @@ impl CertBuilder {
user_attributes: vec![],
password: None,
revocation_keys: None,
+ phantom: PhantomData,
}
}
@@ -273,6 +276,7 @@ impl CertBuilder {
user_attributes: vec![],
password: None,
revocation_keys: None,
+ phantom: PhantomData,
}
}