diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-11-19 15:50:23 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-11-19 15:50:23 +0100 |
commit | 1ddc1dd61b45b41801c1d1c364cd6789314cb8f3 (patch) | |
tree | b34baf591fce5f778cd2f132ead705d39abbff47 /openpgp/examples | |
parent | cf9b92f5f9238b8322d09833b92c886dda219924 (diff) |
openpgp: Use the builder pattern for stream::Signer.
- See #375.
Diffstat (limited to 'openpgp/examples')
-rw-r--r-- | openpgp/examples/generate-sign-verify.rs | 4 | ||||
-rw-r--r-- | openpgp/examples/notarize.rs | 16 | ||||
-rw-r--r-- | openpgp/examples/sign-detached.rs | 15 | ||||
-rw-r--r-- | openpgp/examples/sign.rs | 16 |
4 files changed, 24 insertions, 27 deletions
diff --git a/openpgp/examples/generate-sign-verify.rs b/openpgp/examples/generate-sign-verify.rs index bddacc71..e22e5760 100644 --- a/openpgp/examples/generate-sign-verify.rs +++ b/openpgp/examples/generate-sign-verify.rs @@ -40,14 +40,14 @@ fn generate() -> openpgp::Result<openpgp::TPK> { fn sign(sink: &mut dyn Write, plaintext: &str, tsk: &openpgp::TPK) -> openpgp::Result<()> { // Get the keypair to do the signing from the TPK. - let mut keypair = tsk.keys_valid().signing_capable().nth(0).unwrap().2 + let keypair = tsk.keys_valid().signing_capable().nth(0).unwrap().2 .clone().mark_parts_secret().into_keypair()?; // Start streaming an OpenPGP message. let message = Message::new(sink); // We want to sign a literal data packet. - let signer = Signer::new(message, vec![&mut keypair], None)?; + let signer = Signer::new(message, keypair).build()?; // Emit a literal data packet. let mut literal_writer = LiteralWriter::new(signer, None, None, None)?; diff --git a/openpgp/examples/notarize.rs b/openpgp/examples/notarize.rs index eedcc01e..c627d4f1 100644 --- a/openpgp/examples/notarize.rs +++ b/openpgp/examples/notarize.rs @@ -7,7 +7,6 @@ use std::io; extern crate sequoia_openpgp as openpgp; use crate::openpgp::{ armor, - crypto, Packet, parse::{Parse, PacketParserResult}, serialize::Serialize, @@ -60,14 +59,13 @@ fn main() { // Stream an OpenPGP message. let message = Message::new(sink); - // Now, create a signer that emits a detached signature. - let mut signer = Signer::new( - message, - keys.iter_mut() - .map(|s| -> &mut dyn crypto::Signer<_> { s }) - .collect(), - None) - .expect("Failed to create signer"); + // Now, create a signer that emits the signature(s). + let mut signer = + Signer::new(message, keys.pop().expect("No key for signing")); + for s in keys { + signer = signer.add_signer(s); + } + let mut signer = signer.build().expect("Failed to create signer"); // Create a parser for the message to be notarized. let mut input = io::stdin(); diff --git a/openpgp/examples/sign-detached.rs b/openpgp/examples/sign-detached.rs index d4d8d40d..98202bd2 100644 --- a/openpgp/examples/sign-detached.rs +++ b/openpgp/examples/sign-detached.rs @@ -6,7 +6,6 @@ extern crate rpassword; extern crate sequoia_openpgp as openpgp; use crate::openpgp::armor; -use crate::openpgp::crypto; use crate::openpgp::parse::Parse; use crate::openpgp::serialize::stream::{Message, Signer}; @@ -56,12 +55,14 @@ fn main() { // Stream an OpenPGP message. let message = Message::new(sink); - // Now, create a signer that emits a detached signature. - let mut signer = Signer::detached( - message, - keys.iter_mut().map(|s| -> &mut dyn crypto::Signer<_> { s }).collect(), - None) - .expect("Failed to create signer"); + // Now, create a signer that emits the detached signature(s). + let mut signer = + Signer::new(message, keys.pop().expect("No key for signing")); + for s in keys { + signer = signer.add_signer(s); + } + let mut signer = + signer.detached().build().expect("Failed to create signer"); // Copy all the data. io::copy(&mut io::stdin(), &mut signer) diff --git a/openpgp/examples/sign.rs b/openpgp/examples/sign.rs index 7a7bcd91..2304865f 100644 --- a/openpgp/examples/sign.rs +++ b/openpgp/examples/sign.rs @@ -5,7 +5,6 @@ use std::io; extern crate sequoia_openpgp as openpgp; use crate::openpgp::armor; -use crate::openpgp::crypto; use crate::openpgp::parse::Parse; use crate::openpgp::serialize::stream::{Message, LiteralWriter, Signer}; @@ -55,14 +54,13 @@ fn main() { // Stream an OpenPGP message. let message = Message::new(sink); - // Now, create a signer that emits a signature. - let signer = Signer::new( - message, - keys.iter_mut() - .map(|s| -> &mut dyn crypto::Signer<_> { s }) - .collect(), - None) - .expect("Failed to create signer"); + // Now, create a signer that emits the signature(s). + let mut signer = + Signer::new(message, keys.pop().expect("No key for signing")); + for s in keys { + signer = signer.add_signer(s); + } + let signer = signer.build().expect("Failed to create signer"); // Then, create a literal writer to wrap the data in a literal // message packet. |