|
38 | 38 | //! methods accept any type that impls the [`aead::Buffer`] trait which |
39 | 39 | //! contains the plaintext for encryption or ciphertext for decryption. |
40 | 40 | //! |
41 | | -//! Note that if you enable the `heapless` feature of this crate, |
42 | | -//! you will receive an impl of [`aead::Buffer`] for `heapless::Vec` |
43 | | -//! (re-exported from the [`aead`] crate as [`aead::heapless::Vec`]), |
44 | | -//! which can then be passed as the `buffer` parameter to the in-place encrypt |
| 41 | +//! Enabling the `arrayvec` feature of this crate will provide an impl of |
| 42 | +//! [`aead::Buffer`] for `arrayvec::ArrayVec` (re-exported from the [`aead`] crate as |
| 43 | +//! [`aead::arrayvec::ArrayVec`]), and enabling the `bytes` feature of this crate will |
| 44 | +//! provide an impl of [`aead::Buffer`] for `bytes::BytesMut` (re-exported from the |
| 45 | +//! [`aead`] crate as [`aead::bytes::BytesMut`]). |
| 46 | +//! |
| 47 | +//! It can then be passed as the `buffer` parameter to the in-place encrypt |
45 | 48 | //! and decrypt methods: |
46 | 49 | //! |
47 | | -#![cfg_attr(all(feature = "os_rng", feature = "heapless"), doc = "```")] |
48 | | -#![cfg_attr(not(all(feature = "os_rng", feature = "heapless")), doc = "```ignore")] |
| 50 | +#![cfg_attr(all(feature = "os_rng", feature = "arrayvec"), doc = "```")] |
| 51 | +#![cfg_attr(not(all(feature = "os_rng", feature = "arrayvec")), doc = "```ignore")] |
49 | 52 | //! # fn main() -> Result<(), Box<dyn std::error::Error>> { |
50 | 53 | //! use aes_gcm_siv::{ |
51 | | -//! aead::{AeadInOut, KeyInit, rand_core::OsRng, heapless::Vec}, |
| 54 | +//! aead::{AeadInOut, Buffer, KeyInit, rand_core::OsRng, arrayvec::ArrayVec}, |
52 | 55 | //! Aes256GcmSiv, Nonce, // Or `Aes128GcmSiv` |
53 | 56 | //! }; |
54 | 57 | //! |
55 | 58 | //! let key = Aes256GcmSiv::generate_key().expect("generate key"); |
56 | 59 | //! let cipher = Aes256GcmSiv::new(&key); |
57 | 60 | //! let nonce = Nonce::from_slice(b"unique nonce"); // 96-bits; unique per message |
58 | 61 | //! |
59 | | -//! let mut buffer: Vec<u8, 128> = Vec::new(); // Note: buffer needs 16-bytes overhead for auth tag |
| 62 | +//! let mut buffer: ArrayVec<u8, 128> = ArrayVec::new(); // Note: buffer needs 16-bytes overhead for auth tag |
60 | 63 | //! buffer.extend_from_slice(b"plaintext message"); |
61 | 64 | //! |
62 | 65 | //! // Encrypt `buffer` in-place, replacing the plaintext contents with ciphertext |
63 | 66 | //! cipher.encrypt_in_place(nonce, b"", &mut buffer)?; |
64 | 67 | //! |
65 | 68 | //! // `buffer` now contains the message ciphertext |
66 | | -//! assert_ne!(&buffer, b"plaintext message"); |
| 69 | +//! assert_ne!(buffer.as_ref(), b"plaintext message"); |
67 | 70 | //! |
68 | 71 | //! // Decrypt `buffer` in-place, replacing its ciphertext context with the original plaintext |
69 | 72 | //! cipher.decrypt_in_place(nonce, b"", &mut buffer)?; |
70 | | -//! assert_eq!(&buffer, b"plaintext message"); |
| 73 | +//! assert_eq!(buffer.as_ref(), b"plaintext message"); |
71 | 74 | //! # Ok(()) |
72 | 75 | //! # } |
73 | 76 | //! ``` |
74 | | -//! |
75 | | -//! Similarly, enabling the `arrayvec` feature of this crate will provide an impl of |
76 | | -//! [`aead::Buffer`] for `arrayvec::ArrayVec` (re-exported from the [`aead`] crate as |
77 | | -//! [`aead::arrayvec::ArrayVec`]), and enabling the `bytes` feature of this crate will |
78 | | -//! provide an impl of [`aead::Buffer`] for `bytes::BytesMut` (re-exported from the |
79 | | -//! [`aead`] crate as [`aead::bytes::BytesMut`]). |
80 | 77 |
|
81 | 78 | pub use aead::{self, AeadCore, AeadInOut, Error, Key, KeyInit, KeySizeUser}; |
82 | 79 |
|
|
0 commit comments