diff options
-rw-r--r-- | openpgp-ffi/src/key_amalgamation.rs | 21 | ||||
-rw-r--r-- | openpgp/src/cert/amalgamation/key.rs | 16 |
2 files changed, 20 insertions, 17 deletions
diff --git a/openpgp-ffi/src/key_amalgamation.rs b/openpgp-ffi/src/key_amalgamation.rs index 0b661533..d25fb2bc 100644 --- a/openpgp-ffi/src/key_amalgamation.rs +++ b/openpgp-ffi/src/key_amalgamation.rs @@ -16,7 +16,6 @@ use self::openpgp::crypto; use super::packet::key::Key; use super::packet::signature::Signature; -use super::packet::Packet; use super::policy::Policy; use super::revocation_status::RevocationStatus; @@ -107,7 +106,7 @@ fn pgp_valid_key_amalgamation_set_expiration_time( ka: *const ValidKeyAmalgamation, primary_signer: *mut Box<dyn crypto::Signer>, expiry: time_t, - packets: *mut *mut *mut Packet, packet_count: *mut size_t) + sigs: *mut *mut *mut Signature, sig_count: *mut size_t) -> Status { ffi_make_fry_from_errp!(errp); @@ -115,22 +114,22 @@ fn pgp_valid_key_amalgamation_set_expiration_time( let ka = ka.ref_raw(); let signer = ffi_param_ref_mut!(primary_signer); let expiry = maybe_time(expiry); - let packets = ffi_param_ref_mut!(packets); - let packet_count = ffi_param_ref_mut!(packet_count); + let sigs = ffi_param_ref_mut!(sigs); + let sig_count = ffi_param_ref_mut!(sig_count); match ka.set_expiration_time(signer.as_mut(), expiry) { - Ok(sigs) => { + Ok(new_sigs) => { let buffer = unsafe { - libc::calloc(sigs.len(), std::mem::size_of::<*mut Packet>()) - as *mut *mut Packet + libc::calloc(new_sigs.len(), std::mem::size_of::<*mut Signature>()) + as *mut *mut Signature }; let sl = unsafe { - slice::from_raw_parts_mut(buffer, sigs.len()) + slice::from_raw_parts_mut(buffer, new_sigs.len()) }; - *packet_count = sigs.len(); - sl.iter_mut().zip(sigs.into_iter()) + *sig_count = new_sigs.len(); + sl.iter_mut().zip(new_sigs.into_iter()) .for_each(|(e, sig)| *e = sig.move_into_raw()); - *packets = buffer; + *sigs = buffer; Status::Success } Err(err) => { diff --git a/openpgp/src/cert/amalgamation/key.rs b/openpgp/src/cert/amalgamation/key.rs index f282b7bb..d1a2acd8 100644 --- a/openpgp/src/cert/amalgamation/key.rs +++ b/openpgp/src/cert/amalgamation/key.rs @@ -266,7 +266,6 @@ use crate::{ cert::ValidCert, crypto::{hash::Hash, Signer}, Error, - Packet, packet::Key, packet::key, packet::key::KeyParts, @@ -1307,7 +1306,7 @@ impl<'a, P, R, R2> ValidKeyAmalgamation<'a, P, R, R2> primary_signer: &mut dyn Signer, expiration: Option<time::Duration>, now: time::SystemTime) - -> Result<Vec<Packet>> + -> Result<Vec<Signature>> { let hash_algo = HashAlgorithm::SHA512; let mut sigs = Vec::new(); @@ -1332,7 +1331,7 @@ impl<'a, P, R, R2> ValidKeyAmalgamation<'a, P, R, R2> sigs.push(builder .set_key_validity_period(expiration)? .set_signature_creation_time(now)? - .sign_hash(primary_signer, hash)?.into()); + .sign_hash(primary_signer, hash)?); // Second, generate a new binding signature for every // userid. We need to be careful not to change the @@ -1352,7 +1351,7 @@ impl<'a, P, R, R2> ValidKeyAmalgamation<'a, P, R, R2> self.cert().primary_userid().map(|primary| { userid.userid() == primary.userid() }).unwrap_or(false))? - .sign_hash(primary_signer, hash)?.into()); + .sign_hash(primary_signer, hash)?); } } else { // To extend the validity of the subkey, create a new @@ -1363,7 +1362,7 @@ impl<'a, P, R, R2> ValidKeyAmalgamation<'a, P, R, R2> sigs.push(signature::SignatureBuilder::from(self.binding_signature().clone()) .set_key_validity_period(expiration)? .set_signature_creation_time(now)? - .sign_hash(primary_signer, hash)?.into()); + .sign_hash(primary_signer, hash)?); } Ok(sigs) @@ -1426,6 +1425,10 @@ impl<'a, P, R, R2> ValidKeyAmalgamation<'a, P, R, R2> /// .flat_map(|ka| { /// ka.set_expiration_time(&mut signer, Some(t)).unwrap() /// }) + /// // The iterator needs to run to completion before we + /// // Cert::merge_packets, because the iterator has a reference + /// // to cert (via vc), but Cert::merge_packets needs to take + /// // ownership of it. /// .collect::<Vec<_>>(); /// let cert = cert.merge_packets(sigs)?; /// @@ -1446,7 +1449,7 @@ impl<'a, P, R, R2> ValidKeyAmalgamation<'a, P, R, R2> pub fn set_expiration_time(&self, primary_signer: &mut dyn Signer, expiration: Option<time::SystemTime>) - -> Result<Vec<Packet>> + -> Result<Vec<Signature>> { let expiration = if let Some(e) = expiration.map(crate::types::normalize_systemtime) @@ -1878,6 +1881,7 @@ impl<'a, P, R, R2> ValidKeyAmalgamation<'a, P, R, R2> mod test { use crate::policy::StandardPolicy as P; use crate::cert::prelude::*; + use crate::packet::Packet; use super::*; |