diff options
author | Azul <azul@riseup.net> | 2020-11-28 10:34:10 +0100 |
---|---|---|
committer | Azul <azul@riseup.net> | 2020-12-01 16:23:30 +0100 |
commit | 47dd56257e024aa813ed40bd1a207a9974d3207a (patch) | |
tree | eb33111bca9a773ac3049da42b465485d62c5948 /openpgp/src | |
parent | 5c0cd1775fadc46e68a24a5af3d1f06803d69c4b (diff) |
openpgp: take ownership of Features bitfield
- Since `set_features` requires ownership of `Features`, it should take
ownership rather than borrowing and cloning them.
See https://rust-lang.github.io/api-guidelines/flexibility.html#caller-decides-where-to-copy-and-place-data-c-caller-control .
- See #616.
Diffstat (limited to 'openpgp/src')
-rw-r--r-- | openpgp/src/cert.rs | 6 | ||||
-rw-r--r-- | openpgp/src/cert/builder.rs | 4 | ||||
-rw-r--r-- | openpgp/src/packet/signature/subpacket.rs | 16 | ||||
-rw-r--r-- | openpgp/src/types/mod.rs | 2 |
4 files changed, 14 insertions, 14 deletions
diff --git a/openpgp/src/cert.rs b/openpgp/src/cert.rs index 2e25ad62..bc274021 100644 --- a/openpgp/src/cert.rs +++ b/openpgp/src/cert.rs @@ -4433,7 +4433,7 @@ mod test { let mut pair = key.clone().into_keypair().unwrap(); let (bind1, rev1, bind2, rev2) = { let bind1 = signature::SignatureBuilder::new(SignatureType::DirectKey) - .set_features(&Features::sequoia()).unwrap() + .set_features(Features::sequoia()).unwrap() .set_key_flags(KeyFlags::empty()).unwrap() .set_signature_creation_time(t1).unwrap() .set_key_validity_period(Some(time::Duration::new(10 * 52 * 7 * 24 * 60 * 60, 0))).unwrap() @@ -4447,7 +4447,7 @@ mod test { .sign_direct_key(&mut pair, key.parts_as_public()).unwrap(); let bind2 = signature::SignatureBuilder::new(SignatureType::DirectKey) - .set_features(&Features::sequoia()).unwrap() + .set_features(Features::sequoia()).unwrap() .set_key_flags(KeyFlags::empty()).unwrap() .set_signature_creation_time(t3).unwrap() .set_key_validity_period(Some(time::Duration::new(10 * 52 * 7 * 24 * 60 * 60, 0))).unwrap() @@ -5116,7 +5116,7 @@ Pu1xwz57O4zo1VYf6TqHJzVC3OMvMUM2hhdecMUe5x6GorNaj6g= for (t, offset) in &[ (t2, 0), (t4, 0), (t3, 1 * N), (t1, 3 * N) ] { for i in 0..N { let binding = signature::SignatureBuilder::new(SignatureType::DirectKey) - .set_features(&Features::sequoia()).unwrap() + .set_features(Features::sequoia()).unwrap() .set_key_flags(KeyFlags::empty()).unwrap() .set_signature_creation_time(t1).unwrap() // Vary this... diff --git a/openpgp/src/cert/builder.rs b/openpgp/src/cert/builder.rs index 6d79a910..660b9cfa 100644 --- a/openpgp/src/cert/builder.rs +++ b/openpgp/src/cert/builder.rs @@ -1039,7 +1039,7 @@ impl CertBuilder<'_> { .set_signature_creation_time(creation_time)? // GnuPG wants at least a 512-bit hash for P521 keys. .set_hash_algo(HashAlgorithm::SHA512) - .set_features(&Features::sequoia())? + .set_features(Features::sequoia())? .set_key_flags(flags.clone())? .set_key_validity_period(blueprint.validity.or(self.primary.validity))?; @@ -1088,7 +1088,7 @@ impl CertBuilder<'_> { let mut sig = signature::SignatureBuilder::new(SignatureType::DirectKey) // GnuPG wants at least a 512-bit hash for P521 keys. .set_hash_algo(HashAlgorithm::SHA512) - .set_features(&Features::sequoia())? + .set_features(Features::sequoia())? .set_key_flags(self.primary.flags.clone())? .set_signature_creation_time(creation_time)? .set_key_validity_period(self.primary.validity)? diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs index 2d2c5506..e747bd05 100644 --- a/openpgp/src/packet/signature/subpacket.rs +++ b/openpgp/src/packet/signature/subpacket.rs @@ -6241,7 +6241,7 @@ impl signature::SignatureBuilder { /// SignatureBuilder::from(sig.clone()) /// .set_preferred_aead_algorithms(vec![ AEADAlgorithm::EAX ])? /// .set_features( - /// &sig.features().unwrap_or_else(Features::sequoia) + /// sig.features().unwrap_or_else(Features::sequoia) /// .set_aead())? /// .sign_direct_key(&mut signer, None)?); /// } @@ -6252,7 +6252,7 @@ impl signature::SignatureBuilder { /// SignatureBuilder::from(sig.clone()) /// .set_preferred_aead_algorithms(vec![ AEADAlgorithm::EAX ])? /// .set_features( - /// &sig.features().unwrap_or_else(Features::sequoia) + /// sig.features().unwrap_or_else(Features::sequoia) /// .set_aead())? /// .sign_userid_binding(&mut signer, pk, ua.userid())?); /// } @@ -6263,9 +6263,9 @@ impl signature::SignatureBuilder { /// # Ok(()) /// # } /// ``` - pub fn set_features(mut self, features: &Features) -> Result<Self> { + pub fn set_features(mut self, features: Features) -> Result<Self> { self.hashed_area.replace(Subpacket::new( - SubpacketValue::Features(features.clone()), + SubpacketValue::Features(features), false)?)?; Ok(self) @@ -6619,7 +6619,7 @@ impl signature::SignatureBuilder { /// SignatureBuilder::from(sig.clone()) /// .set_preferred_aead_algorithms(vec![ AEADAlgorithm::EAX ])? /// .set_features( - /// &sig.features().unwrap_or_else(Features::sequoia) + /// sig.features().unwrap_or_else(Features::sequoia) /// .set_aead())? /// .sign_direct_key(&mut signer, None)?); /// } @@ -6630,7 +6630,7 @@ impl signature::SignatureBuilder { /// SignatureBuilder::from(sig.clone()) /// .set_preferred_aead_algorithms(vec![ AEADAlgorithm::EAX ])? /// .set_features( - /// &sig.features().unwrap_or_else(Features::sequoia) + /// sig.features().unwrap_or_else(Features::sequoia) /// .set_aead())? /// .sign_userid_binding(&mut signer, pk, ua.userid())?); /// } @@ -7000,13 +7000,13 @@ fn accessors() { Some((ReasonForRevocation::KeyRetired, &b"foobar"[..]))); let feats = Features::empty().set_mdc(); - sig = sig.set_features(&feats).unwrap(); + sig = sig.set_features(feats.clone()).unwrap(); let sig_ = sig.clone().sign_hash(&mut keypair, hash.clone()).unwrap(); assert_eq!(sig_.features().unwrap(), feats); let feats = Features::empty().set_aead(); - sig = sig.set_features(&feats).unwrap(); + sig = sig.set_features(feats.clone()).unwrap(); let sig_ = sig.clone().sign_hash(&mut keypair, hash.clone()).unwrap(); assert_eq!(sig_.features().unwrap(), feats); diff --git a/openpgp/src/types/mod.rs b/openpgp/src/types/mod.rs index 5872ebb4..4fd25e50 100644 --- a/openpgp/src/types/mod.rs +++ b/openpgp/src/types/mod.rs @@ -691,7 +691,7 @@ impl Arbitrary for SymmetricAlgorithm { /// # fn main() -> openpgp::Result<()> { /// let features = Features::empty().set_aead(); /// let mut builder = SignatureBuilder::new(SignatureType::DirectKey) -/// .set_features(&features)? +/// .set_features(features)? /// .set_preferred_aead_algorithms(vec![ /// AEADAlgorithm::EAX, /// ])?; |