diff --git a/argon2/src/lib.rs b/argon2/src/lib.rs index 0a1b7a29..5fc1f3c7 100644 --- a/argon2/src/lib.rs +++ b/argon2/src/lib.rs @@ -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> { +#![cfg_attr(all(feature = "alloc", feature = "getrandom"), doc = "```")] +#![cfg_attr(not(all(feature = "alloc", feature = "getrandom")), doc = "```ignore")] +//! # fn main() -> Result<(), Box> { //! use argon2::{ //! password_hash::{PasswordHash, PasswordHasher, PasswordVerifier, phc::Salt}, //! Argon2 @@ -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> { +#![cfg_attr(all(feature = "alloc", feature = "getrandom"), doc = "```")] +#![cfg_attr(not(all(feature = "alloc", feature = "getrandom")), doc = "```ignore")] +//! # fn main() -> Result<(), Box> { //! use argon2::{ //! password_hash::{ //! phc::{PasswordHash, Salt}, @@ -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> { +#![cfg_attr(feature = "alloc", doc = "```")] +#![cfg_attr(not(feature = "alloc"), doc = "```ignore")] +//! # fn main() -> Result<(), Box> { //! use argon2::Argon2; //! //! let password = b"hunter42"; // Bad password; don't actually use! diff --git a/balloon-hash/src/error.rs b/balloon-hash/src/error.rs index 8e1c580d..4b1d4c0e 100644 --- a/balloon-hash/src/error.rs +++ b/balloon-hash/src/error.rs @@ -57,5 +57,4 @@ impl From for password_hash::Error { } } -#[cfg(feature = "std")] -impl std::error::Error for Error {} +impl core::error::Error for Error {} diff --git a/balloon-hash/src/lib.rs b/balloon-hash/src/lib.rs index bd6df8d8..d9e963e4 100644 --- a/balloon-hash/src/lib.rs +++ b/balloon-hash/src/lib.rs @@ -30,7 +30,7 @@ //! #![cfg_attr(feature = "getrandom", doc = "```")] #![cfg_attr(not(feature = "getrandom"), doc = "```ignore")] -//! # fn main() -> Result<(), Box> { +//! # fn main() -> Result<(), Box> { //! use balloon_hash::{ //! password_hash::{PasswordHash, PasswordHasher, PasswordVerifier, phc::Salt}, //! Balloon diff --git a/bcrypt-pbkdf/src/errors.rs b/bcrypt-pbkdf/src/errors.rs index cc397267..1176e631 100644 --- a/bcrypt-pbkdf/src/errors.rs +++ b/bcrypt-pbkdf/src/errors.rs @@ -24,5 +24,4 @@ impl fmt::Display for Error { } } -#[cfg(feature = "std")] -impl std::error::Error for Error {} +impl core::error::Error for Error {} diff --git a/password-auth/src/errors.rs b/password-auth/src/errors.rs index 33820e7c..6059d236 100644 --- a/password-auth/src/errors.rs +++ b/password-auth/src/errors.rs @@ -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 { @@ -55,8 +61,11 @@ impl From 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, + } + } +} diff --git a/scrypt/Cargo.toml b/scrypt/Cargo.toml index 5a078ac8..a5362b1b 100644 --- a/scrypt/Cargo.toml +++ b/scrypt/Cargo.toml @@ -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"] diff --git a/scrypt/src/lib.rs b/scrypt/src/lib.rs index 57976860..ceff27ff 100644 --- a/scrypt/src/lib.rs +++ b/scrypt/src/lib.rs @@ -12,20 +12,18 @@ //! //! # Usage (simple with default params) //! -//! ``` -//! # fn main() -> Result<(), Box> { -//! # #[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> { //! 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(); @@ -33,7 +31,6 @@ //! // Verify password against PHC string //! let parsed_hash = PasswordHash::new(&password_hash)?; //! assert!(Scrypt.verify_password(password, &parsed_hash).is_ok()); -//! # } //! # Ok(()) //! # } //! ```