diff options
Diffstat (limited to 'openpgp/examples/generate-encrypt-decrypt.rs')
-rw-r--r-- | openpgp/examples/generate-encrypt-decrypt.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/openpgp/examples/generate-encrypt-decrypt.rs b/openpgp/examples/generate-encrypt-decrypt.rs index 3a02f264..1b1e267b 100644 --- a/openpgp/examples/generate-encrypt-decrypt.rs +++ b/openpgp/examples/generate-encrypt-decrypt.rs @@ -13,21 +13,23 @@ use crate::openpgp::policy::StandardPolicy as P; const MESSAGE: &'static str = "дружба"; -fn main() { +fn main() -> openpgp::Result<()> { let p = &P::new(); // Generate a key. - let key = generate().unwrap(); + let key = generate()?; // Encrypt the message. let mut ciphertext = Vec::new(); - encrypt(p, &mut ciphertext, MESSAGE, &key).unwrap(); + encrypt(p, &mut ciphertext, MESSAGE, &key)?; // Decrypt the message. let mut plaintext = Vec::new(); - decrypt(p, &mut plaintext, &ciphertext, &key).unwrap(); + decrypt(p, &mut plaintext, &ciphertext, &key)?; assert_eq!(MESSAGE.as_bytes(), &plaintext[..]); + + Ok(()) } /// Generates an encryption-capable key. @@ -125,7 +127,7 @@ impl<'a> DecryptionHelper for Helper<'a> { .for_transport_encryption().nth(0).unwrap().key().clone(); // The secret key is not encrypted. - let mut pair = key.into_keypair().unwrap(); + let mut pair = key.into_keypair()?; pkesks[0].decrypt(&mut pair, sym_algo) .map(|(algo, session_key)| decrypt(algo, &session_key)); |