diff --git a/blobby/src/lib.rs b/blobby/src/lib.rs index b7d1737b..665b8b2d 100644 --- a/blobby/src/lib.rs +++ b/blobby/src/lib.rs @@ -51,7 +51,6 @@ extern crate alloc; use alloc::{boxed::Box, collections::BTreeMap, vec, vec::Vec}; -use core::iter::Iterator; /// Iterator over binary blobs pub struct BlobIterator<'a> { diff --git a/dbl/src/lib.rs b/dbl/src/lib.rs index 7cd04e8b..00b49e19 100644 --- a/dbl/src/lib.rs +++ b/dbl/src/lib.rs @@ -9,8 +9,6 @@ use hybrid_array::typenum::{U16, U32, U8}; use hybrid_array::Array; -use core::convert::TryInto; - const C64: u64 = 0b1_1011; const C128: u64 = 0b1000_0111; const C256: u64 = 0b100_0010_0101; diff --git a/zeroize/src/lib.rs b/zeroize/src/lib.rs index 9326d075..6764015e 100644 --- a/zeroize/src/lib.rs +++ b/zeroize/src/lib.rs @@ -41,15 +41,13 @@ //! ``` //! use zeroize::Zeroize; //! -//! fn main() { -//! // Protip: don't embed secrets in your source code. -//! // This is just an example. -//! let mut secret = b"Air shield password: 1,2,3,4,5".to_vec(); -//! // [ ... ] open the air shield here -//! -//! // Now that we're done using the secret, zero it out. -//! secret.zeroize(); -//! } +//! // Protip: don't embed secrets in your source code. +//! // This is just an example. +//! let mut secret = b"Air shield password: 1,2,3,4,5".to_vec(); +//! // [ ... ] open the air shield here +//! +//! // Now that we're done using the secret, zero it out. +//! secret.zeroize(); //! ``` //! //! The [`Zeroize`] trait is impl'd on all of Rust's core scalar types including @@ -68,6 +66,7 @@ //! memory is zeroed by converting it to a `Vec` and back into a `CString`. //! (NOTE: see "Stack/Heap Zeroing Notes" for important `Vec`/`String`/`CString` details) //! +//! [`CString`]: https://doc.rust-lang.org/std/ffi/struct.CString.html //! //! The [`DefaultIsZeroes`] marker trait can be impl'd on types which also //! impl [`Default`], which implements [`Zeroize`] by overwriting a value with @@ -143,7 +142,7 @@ //! ``` //! use zeroize::Zeroizing; //! -//! fn main() { +//! fn use_secret() { //! let mut secret = Zeroizing::new([0u8; 5]); //! //! // Set the air shield password @@ -153,6 +152,8 @@ //! //! // The contents of `secret` will be automatically zeroized on drop //! } +//! +//! # use_secret() //! ``` //! //! ## What guarantees does this crate provide? @@ -800,31 +801,21 @@ unsafe fn volatile_set(dst: *mut T, src: T, count: usize) { /// type that already implements `ZeroizeOnDrop`. /// /// # Safety -/// - The type must not contain references to outside data or dynamically sized data, such as Vec -/// or String. -/// - This function can invalidate the type if it is used after this function is called on it. It is -/// advisable to call this function in `impl Drop`. -/// - The bit pattern of all zeroes must be valid for the data being zeroized. This may not be true for -/// enums and pointers. +/// - The type must not contain references to outside data or dynamically sized data, such as +/// `Vec` or `String`. +/// - Values stored in the type must not have `Drop` impls. +/// - This function can invalidate the type if it is used after this function is called on it. +/// It is advisable to call this function only in `impl Drop`. +/// - The bit pattern of all zeroes must be valid for the data being zeroized. This may not be +/// true for enums and pointers. /// /// # Incompatible data types -/// Some data types that cannot be safely zeroized using `zeroize_flat_type` include, but are not -/// limited to: -/// - pointers such as -/// - *const u8 -/// - *mut u8 -/// - references such as -/// - &T -/// - &mut T -/// - smart pointers and collections -/// - Arc -/// - Box -/// - Vec -/// - HashMap -/// - String -/// -/// Some data types that may be invalid after calling `zeroize_flat_type`: -/// - enums +/// Some data types that cannot be safely zeroized using `zeroize_flat_type` include, +/// but are not limited to: +/// - References: `&T` and `&mut T` +/// - Non-nullable types: `NonNull`, `NonZeroU32`, etc. +/// - Enums with explicit non-zero tags. +/// - Smart pointers and collections: `Arc`, `Box`, `Vec`, `HashMap`, `String`, etc. /// /// # Examples /// Safe usage for a struct containing strictly flat data: diff --git a/zeroize/tests/zeroize_derive.rs b/zeroize/tests/zeroize_derive.rs index c561ba61..e7939bf0 100644 --- a/zeroize/tests/zeroize_derive.rs +++ b/zeroize/tests/zeroize_derive.rs @@ -345,6 +345,7 @@ fn derive_zeroize_with_marker() { field: Option, } + #[allow(dead_code)] trait Secret: ZeroizeOnDrop + Zeroize {} impl Secret for Test {}