Skip to content

Commit d844f36

Browse files
authored
zeroize: incorporate README.md into rustdoc (#1490)
1 parent c65c09d commit d844f36

2 files changed

Lines changed: 31 additions & 47 deletions

File tree

zeroize/README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
[![Crate][crate-image]][crate-link]
44
[![Docs][docs-image]][docs-link]
5+
[![Build Status][build-image]][build-link]
56
![Apache 2.0/MIT Licensed][license-image]
67
![MSRV][rustc-image]
7-
[![Build Status][build-image]][build-link]
8+
[![Project Chat][chat-image]][chat-link]
89

910
Securely zero memory (a.k.a. [zeroize]) while avoiding compiler optimizations.
1011

@@ -34,6 +35,27 @@ thereof, implemented in pure Rust with no usage of FFI or assembly.
3435
- No functionality besides securely zeroing memory!
3536
- (Optional) Custom derive support for zeroing complex structures
3637

38+
## Minimum Supported Rust Version
39+
40+
Requires Rust **1.85** or newer.
41+
42+
In the future, we reserve the right to change MSRV (i.e. MSRV is out-of-scope for this crate's
43+
semantic versioning guarantees).
44+
45+
## Usage
46+
47+
```
48+
use zeroize::Zeroize;
49+
50+
// Protip: don't embed secrets in your source code.
51+
// This is just an example.
52+
let mut secret = b"Air shield password: 1,2,3,4,5".to_vec();
53+
// [ ... ] open the air shield here
54+
55+
// Now that we're done using the secret, zero it out.
56+
secret.zeroize();
57+
```
58+
3759
## License
3860

3961
Licensed under either of:
@@ -53,12 +75,14 @@ dual licensed as above, without any additional terms or conditions.
5375

5476
[crate-image]: https://img.shields.io/crates/v/zeroize.svg
5577
[crate-link]: https://crates.io/crates/zeroize
78+
[build-image]: https://github.com/RustCrypto/utils/actions/workflows/zeroize.yml/badge.svg?branch=master
79+
[build-link]: https://github.com/RustCrypto/utils/actions/workflows/zeroize.yml?query=branch:master
5680
[docs-image]: https://docs.rs/zeroize/badge.svg
5781
[docs-link]: https://docs.rs/zeroize/
5882
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
5983
[rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg
60-
[build-image]: https://github.com/RustCrypto/utils/actions/workflows/zeroize.yml/badge.svg?branch=master
61-
[build-link]: https://github.com/RustCrypto/utils/actions/workflows/zeroize.yml?query=branch:master
84+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
85+
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260052-utils
6286

6387
[//]: # (general links)
6488

zeroize/src/lib.rs

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,13 @@
11
#![no_std]
22
#![cfg_attr(docsrs, feature(doc_cfg))]
3+
#![doc = include_str!("../README.md")]
34
#![doc(
45
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
56
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
67
)]
7-
#![allow(clippy::undocumented_unsafe_blocks)] // TODO(tarcieri): document all unsafe blocks
8+
#![allow(clippy::undocumented_unsafe_blocks, reason = "TODO")]
89

9-
//! Securely zero memory with a simple trait ([`Zeroize`]) built on stable Rust
10-
//! primitives which guarantee the operation will not be "optimized away".
11-
//!
12-
//! ## About
13-
//!
14-
//! [Zeroing memory securely is hard] - compilers optimize for performance, and
15-
//! in doing so they love to "optimize away" unnecessary zeroing calls. There are
16-
//! many documented "tricks" to attempt to avoid these optimizations and ensure
17-
//! that a zeroing routine is performed reliably.
18-
//!
19-
//! This crate isn't about tricks: it uses [`core::ptr::write_volatile`]
20-
//! and [`core::sync::atomic`] memory fences to provide easy-to-use, portable
21-
//! zeroing behavior which works on all of Rust's core number types and slices
22-
//! thereof, implemented in pure Rust with no usage of FFI or assembly.
23-
//!
24-
//! - No insecure fallbacks!
25-
//! - No dependencies!
26-
//! - No FFI or inline assembly! **WASM friendly** (and tested)!
27-
//! - `#![no_std]` i.e. **embedded-friendly**!
28-
//! - No functionality besides securely zeroing memory!
29-
//! - (Optional) Custom derive support for zeroing complex structures
30-
//!
31-
//! ## Minimum Supported Rust Version
32-
//!
33-
//! Requires Rust **1.85** or newer.
34-
//!
35-
//! In the future, we reserve the right to change MSRV (i.e. MSRV is out-of-scope for this crate's
36-
//! semantic versioning guarantees).
37-
//!
38-
//! ## Usage
39-
//!
40-
//! ```
41-
//! use zeroize::Zeroize;
42-
//!
43-
//! // Protip: don't embed secrets in your source code.
44-
//! // This is just an example.
45-
//! let mut secret = b"Air shield password: 1,2,3,4,5".to_vec();
46-
//! // [ ... ] open the air shield here
47-
//!
48-
//! // Now that we're done using the secret, zero it out.
49-
//! secret.zeroize();
50-
//! ```
10+
//! ## Supported types
5111
//!
5212
//! The [`Zeroize`] trait is impl'd on all of Rust's core scalar types including
5313
//! integers, floats, `bool`, and `char`.
@@ -628,7 +588,7 @@ impl Zeroize for CString {
628588
/// `Zeroizing` is a wrapper for any `Z: Zeroize` type which implements a
629589
/// `Drop` handler which zeroizes dropped values.
630590
///
631-
/// Zeroizing<T> is defined with `repr(transparent)`, which means it is
591+
/// `Zeroizing<T>` is defined with `repr(transparent)`, which means it is
632592
/// guaranteed to have the same physical representation as the underlying type.
633593
#[derive(Debug, Default, Eq, PartialEq)]
634594
#[repr(transparent)]

0 commit comments

Comments
 (0)