diff options
Diffstat (limited to 'guide/src/chapter_02.md')
-rw-r--r-- | guide/src/chapter_02.md | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/guide/src/chapter_02.md b/guide/src/chapter_02.md index d00fa669..acc2cb2e 100644 --- a/guide/src/chapter_02.md +++ b/guide/src/chapter_02.md @@ -50,7 +50,7 @@ fn main() { # fn encrypt(sink: &mut Write, plaintext: &str, recipient: &openpgp::TPK) # -> openpgp::Result<()> { # // Build a vector of recipients to hand to Encryptor. -# let recipients = +# let mut recipients = # recipient.keys_valid() # .key_flags(KeyFlags::default() # .set_encrypt_at_rest(true) @@ -62,10 +62,12 @@ fn main() { # let message = Message::new(sink); # # // We want to encrypt a literal data packet. -# let encryptor = Encryptor::new(message, -# &[], // No symmetric encryption. -# &recipients, -# None, None)?; +# let mut encryptor = Encryptor::for_recipient( +# message, recipients.pop().expect("No encryption key found")); +# for r in recipients { +# encryptor = encryptor.add_recipient(r) +# } +# let encryptor = encryptor.build().expect("Failed to create encryptor"); # # // Emit a literal data packet. # let mut literal_writer = LiteralWriter::new(encryptor).build()?; @@ -191,7 +193,7 @@ fn generate() -> openpgp::Result<openpgp::TPK> { # fn encrypt(sink: &mut Write, plaintext: &str, recipient: &openpgp::TPK) # -> openpgp::Result<()> { # // Build a vector of recipients to hand to Encryptor. -# let recipients = +# let mut recipients = # recipient.keys_valid() # .key_flags(KeyFlags::default() # .set_encrypt_at_rest(true) @@ -203,10 +205,12 @@ fn generate() -> openpgp::Result<openpgp::TPK> { # let message = Message::new(sink); # # // We want to encrypt a literal data packet. -# let encryptor = Encryptor::new(message, -# &[], // No symmetric encryption. -# &recipients, -# None, None)?; +# let mut encryptor = Encryptor::for_recipient( +# message, recipients.pop().expect("No encryption key found")); +# for r in recipients { +# encryptor = encryptor.add_recipient(r) +# } +# let encryptor = encryptor.build().expect("Failed to create encryptor"); # # // Emit a literal data packet. # let mut literal_writer = LiteralWriter::new(encryptor).build()?; @@ -332,7 +336,7 @@ implements [`io::Write`], and we simply write the plaintext to it. fn encrypt(sink: &mut Write, plaintext: &str, recipient: &openpgp::TPK) -> openpgp::Result<()> { // Build a vector of recipients to hand to Encryptor. - let recipients = + let mut recipients = recipient.keys_valid() .key_flags(KeyFlags::default() .set_encrypt_at_rest(true) @@ -344,10 +348,12 @@ fn encrypt(sink: &mut Write, plaintext: &str, recipient: &openpgp::TPK) let message = Message::new(sink); // We want to encrypt a literal data packet. - let encryptor = Encryptor::new(message, - &[], // No symmetric encryption. - &recipients, - None, None)?; + let mut encryptor = Encryptor::for_recipient( + message, recipients.pop().expect("No encryption key found")); + for r in recipients { + encryptor = encryptor.add_recipient(r) + } + let encryptor = encryptor.build().expect("Failed to create encryptor"); // Emit a literal data packet. let mut literal_writer = LiteralWriter::new(encryptor).build()?; @@ -487,7 +493,7 @@ Decrypted data can be read from this using [`io::Read`]. # fn encrypt(sink: &mut Write, plaintext: &str, recipient: &openpgp::TPK) # -> openpgp::Result<()> { # // Build a vector of recipients to hand to Encryptor. -# let recipients = +# let mut recipients = # recipient.keys_valid() # .key_flags(KeyFlags::default() # .set_encrypt_at_rest(true) @@ -499,10 +505,12 @@ Decrypted data can be read from this using [`io::Read`]. # let message = Message::new(sink); # # // We want to encrypt a literal data packet. -# let encryptor = Encryptor::new(message, -# &[], // No symmetric encryption. -# &recipients, -# None, None)?; +# let mut encryptor = Encryptor::for_recipient( +# message, recipients.pop().expect("No encryption key found")); +# for r in recipients { +# encryptor = encryptor.add_recipient(r) +# } +# let encryptor = encryptor.build().expect("Failed to create encryptor"); # # // Emit a literal data packet. # let mut literal_writer = LiteralWriter::new(encryptor).build()?; |