Skip to content

Commit

Permalink
argon2: add usage docs (RustCrypto#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri authored Jan 29, 2021
1 parent 72c0896 commit 75b876f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 21 deletions.
43 changes: 22 additions & 21 deletions .github/workflows/argon2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,28 @@ env:
RUSTFLAGS: "-Dwarnings"

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- 1.47.0 # MSRV
- stable
target:
- thumbv7em-none-eabi
- wasm32-unknown-unknown
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
override: true
- run: cargo build --target ${{ matrix.target }} --release --no-default-features
- run: cargo build --target ${{ matrix.target }} --release
- run: cargo build --target ${{ matrix.target }} --release --features zeroize
# TODO(tarcieri): test when new cargo resolver is available (RFC 2957)
# build:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# rust:
# - 1.47.0 # MSRV
# - stable
# target:
# - thumbv7em-none-eabi
# - wasm32-unknown-unknown
# steps:
# - uses: actions/checkout@v1
# - uses: actions-rs/toolchain@v1
# with:
# profile: minimal
# toolchain: ${{ matrix.rust }}
# target: ${{ matrix.target }}
# override: true
# - run: cargo build --target ${{ matrix.target }} --release --no-default-features
# - run: cargo build --target ${{ matrix.target }} --release
# - run: cargo build --target ${{ matrix.target }} --release --features zeroize

test:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions argon2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ zeroize = { version = "1", optional = true }

[dev-dependencies]
hex-literal = "0.3"
password-hash = { version = "0.1", features = ["rand_core"] }
rand_core = { version = "0.6", features = ["std"] }

[features]
default = ["password-hash"]
Expand Down
25 changes: 25 additions & 0 deletions argon2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,31 @@
//! - **Argon2i**: optimized to resist side-channel attacks
//! - **Argon2id**: (default) hybrid version
//!
//! # Usage (simple with default params)
//!
//! ```
//! # #[cfg(feature = "password-hash")]
//! # {
//! use argon2::{
//! Argon2, PasswordHash, PasswordHasher, PasswordVerifier, password_hash::SaltString
//! };
//! use rand_core::OsRng;
//!
//! let password = b"hunter42"; // Bad password; don't actually use!
//! let salt = SaltString::generate(&mut OsRng);
//!
//! // Argon2 with default params (Argon2id v19)
//! let argon2 = Argon2::default();
//!
//! // Hash password to PHC string ($argon2id$v=19$...)
//! let password_hash = argon2.hash_password_simple(password, salt.as_ref()).unwrap().to_string();
//!
//! // Verify password against PHC string
//! let parsed_hash = PasswordHash::new(&password_hash).unwrap();
//! assert!(argon2.verify_password(password, &parsed_hash).is_ok());
//! # }
//! ```
//!
//! # Notes
//!
//! Multithreading has not yet been implemented.
Expand Down

0 comments on commit 75b876f

Please sign in to comment.