diff options
Diffstat (limited to 'openpgp/examples/wrap-literal.rs')
-rw-r--r-- | openpgp/examples/wrap-literal.rs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/openpgp/examples/wrap-literal.rs b/openpgp/examples/wrap-literal.rs index 7f86e164..7f2b6023 100644 --- a/openpgp/examples/wrap-literal.rs +++ b/openpgp/examples/wrap-literal.rs @@ -6,22 +6,24 @@ use std::env; use std::io; +use anyhow::Context; + extern crate sequoia_openpgp as openpgp; use crate::openpgp::armor; use crate::openpgp::serialize::stream::{Message, LiteralWriter}; -fn main() { +fn main() -> openpgp::Result<()> { let args: Vec<String> = env::args().collect(); if args.len() != 1 { - panic!("A simple filter wrapping data into a literal data packet.\n\n\ - Usage: {} <input >output\n", args[0]); + return Err(anyhow::anyhow!("A simple filter wrapping data into a literal data packet.\n\n\ + Usage: {} <input >output\n", args[0])); } // Compose a writer stack corresponding to the output format and // packet structure we want. First, we want the output to be // ASCII armored. let mut sink = armor::Writer::new(io::stdout(), armor::Kind::Message) - .expect("Failed to create armored writer."); + .context("Failed to create armored writer.")?; // Stream an OpenPGP message. let message = Message::new(&mut sink); @@ -29,17 +31,19 @@ fn main() { // Then, create a literal writer to wrap the data in a literal // message packet. let mut literal = LiteralWriter::new(message).build() - .expect("Failed to create literal writer"); + .context("Failed to create literal writer")?; // Copy all the data. io::copy(&mut io::stdin(), &mut literal) - .expect("Failed to sign data"); + .context("Failed to sign data")?; // Finally, teardown the stack to ensure all the data is written. literal.finalize() - .expect("Failed to write data"); + .context("Failed to write data")?; // Finalize the armor writer. sink.finalize() - .expect("Failed to write data"); + .context("Failed to write data")?; + + Ok(()) } |