From 9af8563de88f452e3eb763fd416e2163a2a6e401 Mon Sep 17 00:00:00 2001 From: Sean McGrail <549813+skmcgrail@users.noreply.github.com> Date: Tue, 6 Jun 2023 18:37:24 -0700 Subject: [PATCH] Examples use `?`, not `try!`, not `unwrap` (#146) --- 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..aa658a7c592 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 ///