From fb8c180a057a5c912a88a8d44f53cd53efb1d2d8 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Wed, 13 May 2020 16:48:49 +0200 Subject: openpgp: Avoid constructing vectors of recipients. - Every iterator implements IntoIterator. Simplify accordingly. --- openpgp/src/serialize/stream.rs | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'openpgp/src/serialize') diff --git a/openpgp/src/serialize/stream.rs b/openpgp/src/serialize/stream.rs index c68c2099..9d95610d 100644 --- a/openpgp/src/serialize/stream.rs +++ b/openpgp/src/serialize/stream.rs @@ -97,14 +97,12 @@ //! //! let recipient: Cert = // ... //! # sender.clone(); -//! // Build a vector of recipients to hand to the `Encryptor`. //! // Note: One certificate may contain several suitable encryption keys. //! let recipients = //! recipient.keys().with_policy(p, None).alive().revoked(false) //! // Or `for_storage_encryption()`, for data at rest. //! .for_transport_encryption() -//! .map(|ka| ka.key()) -//! .collect::>(); +//! .map(|ka| ka.key()); //! //! # let mut sink = vec![]; //! let message = Message::new(&mut sink); @@ -1858,13 +1856,11 @@ impl<'a> Recipient<'a> { /// # */ /// )?; /// - /// // Build a vector of recipients to hand to the `Encryptor`. /// let recipients = /// cert.keys().with_policy(p, None).alive().revoked(false) /// // Or `for_storage_encryption()`, for data at rest. /// .for_transport_encryption() - /// .map(|ka| ka.key()) - /// .collect::>(); + /// .map(|ka| ka.key()); /// /// # let mut sink = vec![]; /// let message = Message::new(&mut sink); @@ -1935,7 +1931,6 @@ impl<'a> Recipient<'a> { /// # */ /// )?; /// - /// // Build a vector of recipients to hand to the `Encryptor`. /// let recipients = /// cert.keys().with_policy(p, None).alive().revoked(false) /// // Or `for_storage_encryption()`, for data at rest. @@ -2007,7 +2002,6 @@ impl<'a> Recipient<'a> { /// # */ /// )?; /// - /// // Build a vector of recipients to hand to the `Encryptor`. /// let recipients = /// cert.keys().with_policy(p, None).alive().revoked(false) /// // Or `for_storage_encryption()`, for data at rest. @@ -2017,8 +2011,7 @@ impl<'a> Recipient<'a> { /// // Set the recipient keyid to the wildcard id. /// r.set_keyid(KeyID::wildcard()); /// r - /// }) - /// .collect::>(); + /// }); /// /// # let mut sink = vec![]; /// let message = Message::new(&mut sink); @@ -2117,13 +2110,11 @@ impl<'a> Encryptor<'a> { /// # */ /// )?; /// - /// // Build a vector of recipients to hand to the `Encryptor`. /// let recipients = /// cert.keys().with_policy(p, None).alive().revoked(false) /// // Or `for_storage_encryption()`, for data at rest. /// .for_transport_encryption() - /// .map(|ka| ka.key()) - /// .collect::>(); + /// .map(|ka| ka.key()); /// /// # let mut sink = vec![]; /// let message = Message::new(&mut sink); @@ -2252,13 +2243,11 @@ impl<'a> Encryptor<'a> { /// # */ /// )?; /// - /// // Build a vector of recipients to hand to the `Encryptor`. /// let recipients = /// cert.keys().with_policy(p, None).alive().revoked(false) /// // Or `for_storage_encryption()`, for data at rest. /// .for_transport_encryption() - /// .map(|ka| ka.key()) - /// .collect::>(); + /// .map(|ka| ka.key()); /// /// # let mut sink = vec![]; /// let message = Message::new(&mut sink); @@ -2338,13 +2327,11 @@ impl<'a> Encryptor<'a> { /// # */ /// )?; /// - /// // Build a vector of recipients to hand to the `Encryptor`. /// let recipients = /// cert.keys().with_policy(p, None).alive().revoked(false) /// // Or `for_storage_encryption()`, for data at rest. /// .for_transport_encryption() - /// .map(|ka| ka.key()) - /// .collect::>(); + /// .map(|ka| ka.key()); /// /// # let mut sink = vec![]; /// let message = Message::new(&mut sink); @@ -3082,7 +3069,7 @@ mod test { let recipients = tsk .keys().with_policy(p, None) .for_storage_encryption().for_transport_encryption() - .map(|ka| ka.key()).collect::>(); + .map(|ka| ka.key()); let encryptor = Encryptor::for_recipients(m, recipients) .aead_algo(AEADAlgorithm::EAX) .build().unwrap(); -- cgit v1.2.3