Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions argon2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@
//! password-based authentication. Do not use this API to derive cryptographic
//! keys: see the "key derivation" usage example below.
//!
#![cfg_attr(all(feature = "password-hash", feature = "std"), doc = "```")]
#![cfg_attr(
not(all(feature = "password-hash", feature = "std")),
doc = "```ignore"
)]
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
#![cfg_attr(all(feature = "alloc", feature = "getrandom"), doc = "```")]
#![cfg_attr(not(all(feature = "alloc", feature = "getrandom")), doc = "```ignore")]
//! # fn main() -> Result<(), Box<dyn core::error::Error>> {
//! use argon2::{
//! password_hash::{PasswordHash, PasswordHasher, PasswordVerifier, phc::Salt},
//! Argon2
Expand Down Expand Up @@ -66,12 +63,9 @@
//!
//! [pepper]: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#peppering
//!
#![cfg_attr(all(feature = "password-hash", feature = "std"), doc = "```")]
#![cfg_attr(
not(all(feature = "password-hash", feature = "std")),
doc = "```ignore"
)]
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
#![cfg_attr(all(feature = "alloc", feature = "getrandom"), doc = "```")]
#![cfg_attr(not(all(feature = "alloc", feature = "getrandom")), doc = "```ignore")]
//! # fn main() -> Result<(), Box<dyn core::error::Error>> {
//! use argon2::{
//! password_hash::{
//! phc::{PasswordHash, Salt},
Expand Down Expand Up @@ -118,12 +112,9 @@
//! This API is useful for transforming a password into cryptographic keys for
//! e.g. password-based encryption.
//!
#![cfg_attr(all(feature = "password-hash", feature = "std"), doc = "```")]
#![cfg_attr(
not(all(feature = "password-hash", feature = "std")),
doc = "```ignore"
)]
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
#![cfg_attr(feature = "alloc", doc = "```")]
#![cfg_attr(not(feature = "alloc"), doc = "```ignore")]
//! # fn main() -> Result<(), Box<dyn core::error::Error>> {
//! use argon2::Argon2;
//!
//! let password = b"hunter42"; // Bad password; don't actually use!
Expand Down
3 changes: 1 addition & 2 deletions balloon-hash/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,4 @@ impl From<Error> for password_hash::Error {
}
}

#[cfg(feature = "std")]
impl std::error::Error for Error {}
impl core::error::Error for Error {}
2 changes: 1 addition & 1 deletion balloon-hash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
//!
#![cfg_attr(feature = "getrandom", doc = "```")]
#![cfg_attr(not(feature = "getrandom"), doc = "```ignore")]
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # fn main() -> Result<(), Box<dyn core::error::Error>> {
//! use balloon_hash::{
//! password_hash::{PasswordHash, PasswordHasher, PasswordVerifier, phc::Salt},
//! Balloon
Expand Down
3 changes: 1 addition & 2 deletions bcrypt-pbkdf/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ impl fmt::Display for Error {
}
}

#[cfg(feature = "std")]
impl std::error::Error for Error {}
impl core::error::Error for Error {}
19 changes: 14 additions & 5 deletions password-auth/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ impl fmt::Display for ParseError {
}
}

impl core::error::Error for ParseError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
Some(&self.0)
}
}

/// Password verification errors.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum VerifyError {
Expand All @@ -55,8 +61,11 @@ impl From<ParseError> for VerifyError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for ParseError {}

#[cfg(feature = "std")]
impl std::error::Error for VerifyError {}
impl core::error::Error for VerifyError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::Parse(err) => Some(err),
_ => None,
}
}
}
3 changes: 3 additions & 0 deletions scrypt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ phc = { version = "0.6.0-rc.0", optional = true, features = ["rand_core"] }

[features]
default = ["simple", "rayon"]
alloc = ["password-hash?/alloc"]

getrandom = ["simple", "phc/getrandom"]
rayon = ["dep:rayon"]
simple = ["dep:password-hash", "dep:phc"]

Expand Down
13 changes: 5 additions & 8 deletions scrypt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,25 @@
//!
//! # Usage (simple with default params)
//!
//! ```
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # #[cfg(all(feature = "simple", feature = "std"))]
//! # {
#![cfg_attr(all(feature = "alloc", feature = "getrandom"), doc = "```")]
#![cfg_attr(not(all(feature = "alloc", feature = "getrandom")), doc = "```ignore")]
//! # fn main() -> Result<(), Box<dyn core::error::Error>> {
//! use scrypt::{
//! password_hash::{
//! rand_core::OsRng,
//! PasswordHash, PasswordHasher, PasswordVerifier, SaltString
//! PasswordHasher, PasswordVerifier, phc::{PasswordHash, Salt}
//! },
//! Scrypt
//! };
//!
//! let password = b"hunter42"; // Bad password; don't actually use!
//! let salt = SaltString::generate(&mut OsRng);
//! let salt = Salt::generate();
//!
//! // Hash password to PHC string ($scrypt$...)
//! let password_hash = Scrypt.hash_password(password, &salt)?.to_string();
//!
//! // Verify password against PHC string
//! let parsed_hash = PasswordHash::new(&password_hash)?;
//! assert!(Scrypt.verify_password(password, &parsed_hash).is_ok());
//! # }
//! # Ok(())
//! # }
//! ```
Expand Down