From dcc43ef7ac912218e341070b7aaa54c165b6c1d5 Mon Sep 17 00:00:00 2001 From: Sean McGrail Date: Tue, 6 Jun 2023 18:10:59 -0700 Subject: [PATCH] Examples use `?`, not `try!`, not `unwrap` --- aws-lc-rs/src/cipher.rs | 43 +++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/aws-lc-rs/src/cipher.rs b/aws-lc-rs/src/cipher.rs index 794f9672fa1..c2abc41143f 100644 --- a/aws-lc-rs/src/cipher.rs +++ b/aws-lc-rs/src/cipher.rs @@ -21,7 +21,10 @@ //! //! ## AES-128 CBC Mode Encryption //! -//! ``` +//! ```rust +//! # use std::error::Error; +//! # +//! # fn main() -> Result<(), Box> { //! use aws_lc_rs::cipher::{ //! PaddedBlockDecryptingKey, PaddedBlockEncryptingKey, UnboundCipherKey, AES_128, //! }; @@ -33,18 +36,25 @@ //! 0xd1, //! ]; //! -//! let key = UnboundCipherKey::new(&AES_128, key_bytes).unwrap(); -//! let encrypting_key = PaddedBlockEncryptingKey::cbc_pkcs7(key).unwrap(); -//! let context = encrypting_key.encrypt(&mut plaintext).unwrap(); +//! let key = UnboundCipherKey::new(&AES_128, key_bytes)?; +//! let encrypting_key = PaddedBlockEncryptingKey::cbc_pkcs7(key)?; +//! let context = encrypting_key.encrypt(&mut plaintext)?; //! -//! let key = UnboundCipherKey::new(&AES_128, key_bytes).unwrap(); -//! let decrypting_key = PaddedBlockDecryptingKey::cbc_pkcs7(key, context).unwrap(); -//! let plaintext = decrypting_key.decrypt(&mut plaintext).unwrap(); +//! let key = UnboundCipherKey::new(&AES_128, key_bytes)?; +//! let decrypting_key = PaddedBlockDecryptingKey::cbc_pkcs7(key, context)?; +//! let plaintext = decrypting_key.decrypt(&mut plaintext)?; +//! # +//! # +//! Ok(()) +//! # } //! ``` //! //! ## AES-128 CTR Mode Encryption //! -//! ``` +//! ```rust +//! # use std::error::Error; +//! # +//! # fn main() -> Result<(), Box> { //! use aws_lc_rs::cipher::{DecryptingKey, EncryptingKey, UnboundCipherKey, AES_128}; //! //! let mut plaintext = Vec::from("This is a secret message!"); @@ -54,13 +64,16 @@ //! 0xd1, //! ]; //! -//! let key = UnboundCipherKey::new(&AES_128, key_bytes).unwrap(); -//! let encrypting_key = EncryptingKey::ctr(key).unwrap(); -//! let context = encrypting_key.encrypt(&mut plaintext).unwrap(); +//! let key = UnboundCipherKey::new(&AES_128, key_bytes)?; +//! let encrypting_key = EncryptingKey::ctr(key)?; +//! let context = encrypting_key.encrypt(&mut plaintext)?; //! -//! let key = UnboundCipherKey::new(&AES_128, key_bytes).unwrap(); -//! let decrypting_key = DecryptingKey::ctr(key, context).unwrap(); -//! let plaintext = decrypting_key.decrypt(&mut plaintext).unwrap(); +//! let key = UnboundCipherKey::new(&AES_128, key_bytes)?; +//! let decrypting_key = DecryptingKey::ctr(key, context)?; +//! let plaintext = decrypting_key.decrypt(&mut plaintext)?; +//! # +//! # Ok(()) +//! # } //! ``` //! @@ -252,7 +265,7 @@ pub struct UnboundCipherKey { } impl UnboundCipherKey { - /// Constructs a [`UnboundCipherKey`]. + /// Constructs an [`UnboundCipherKey`]. /// /// # Errors ///