From f080e2caf085566c161d18f06fa980f5a275c9b2 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Mon, 17 Jan 2022 18:29:17 -0700 Subject: [PATCH] password-hash: Rust 2021 edition upgrade Upgrades the edition to 2021: deduplicating documentation between README.md and lib.rs and removing explicit `TryFrom`/`TryInto` imports. --- Cargo.lock | 15 ------- Cargo.toml | 1 - elliptic-curve/src/lib.rs | 6 +-- password-hash/Cargo.lock | 62 ++++++++++++++++++++++++++++ password-hash/Cargo.toml | 7 +++- password-hash/README.md | 25 ++++++++--- password-hash/src/ident.rs | 3 +- password-hash/src/lib.rs | 50 ++++++---------------- password-hash/src/output.rs | 2 +- password-hash/src/params.rs | 3 +- password-hash/src/salt.rs | 5 +-- password-hash/src/traits.rs | 5 +-- password-hash/src/value.rs | 3 +- password-hash/tests/hashing.rs | 1 - password-hash/tests/password_hash.rs | 1 - 15 files changed, 108 insertions(+), 81 deletions(-) create mode 100644 password-hash/Cargo.lock diff --git a/Cargo.lock b/Cargo.lock index c8da2e442..96ff03900 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,12 +31,6 @@ dependencies = [ "syn", ] -[[package]] -name = "base64ct" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a32fd6af2b5827bce66c29053ba0e7c42b9dcab01835835058558c10851a46b" - [[package]] name = "blobby" version = "0.3.1" @@ -197,15 +191,6 @@ dependencies = [ "scopeguard", ] -[[package]] -name = "password-hash" -version = "0.4.0-pre" -dependencies = [ - "base64ct", - "rand_core", - "subtle", -] - [[package]] name = "proc-macro-hack" version = "0.5.19" diff --git a/Cargo.toml b/Cargo.toml index c0e881aa2..8484c3c8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,6 @@ members = [ "cipher", "crypto-common", "digest", - "password-hash", "signature", "signature/async", "universal-hash", diff --git a/elliptic-curve/src/lib.rs b/elliptic-curve/src/lib.rs index 27a738536..0cc7dc54c 100644 --- a/elliptic-curve/src/lib.rs +++ b/elliptic-curve/src/lib.rs @@ -1,13 +1,13 @@ #![no_std] #![cfg_attr(docsrs, feature(doc_cfg))] -#![forbid(unsafe_code, clippy::unwrap_used)] -#![warn(missing_docs, rust_2018_idioms, unused_qualifications)] +#![doc = include_str!("../README.md")] #![doc( html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg", html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg", html_root_url = "https://docs.rs/elliptic-curve/0.12.0-pre" )] -#![doc = include_str!("../README.md")] +#![forbid(unsafe_code, clippy::unwrap_used)] +#![warn(missing_docs, rust_2018_idioms, unused_qualifications)] //! ## Usage //! diff --git a/password-hash/Cargo.lock b/password-hash/Cargo.lock new file mode 100644 index 000000000..a10c756bb --- /dev/null +++ b/password-hash/Cargo.lock @@ -0,0 +1,62 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "base64ct" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a32fd6af2b5827bce66c29053ba0e7c42b9dcab01835835058558c10851a46b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "getrandom" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "libc" +version = "0.2.112" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" + +[[package]] +name = "password-hash" +version = "0.4.0-pre" +dependencies = [ + "base64ct", + "rand_core", + "subtle", +] + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom", +] + +[[package]] +name = "subtle" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" diff --git a/password-hash/Cargo.toml b/password-hash/Cargo.toml index bb4c70a76..a3260ca5c 100644 --- a/password-hash/Cargo.toml +++ b/password-hash/Cargo.toml @@ -9,11 +9,16 @@ version = "0.4.0-pre" # Also update html_root_url in lib.rs when bumping this authors = ["RustCrypto Developers"] license = "MIT OR Apache-2.0" readme = "README.md" -edition = "2018" documentation = "https://docs.rs/password-hash" repository = "https://github.com/RustCrypto/traits/tree/master/password-hash" categories = ["cryptography", "no-std"] keywords = ["crypt", "mcf", "password", "pbkdf", "phc"] +edition = "2021" +rust-version = "1.57" + +# Hack to allow this crate to coexist with pre-2021 edition crates +[workspace] +members = ["."] [dependencies] base64ct = ">=1, <1.1.0" diff --git a/password-hash/README.md b/password-hash/README.md index e873f2a1c..05ba77239 100644 --- a/password-hash/README.md +++ b/password-hash/README.md @@ -9,14 +9,23 @@ Traits which describe the functionality of [password hashing algorithms]. -Includes a `no_std`-friendly implementation of the [PHC string format] -(a well-defined subset of the Modular Crypt Format a.k.a. MCF) which -uses the traits this crate defines. +[Documentation][docs-link] + +## About + +Provides a `no_std`-friendly implementation of the +[Password Hashing Competition (PHC) string format specification][PHC] +(a well-defined subset of the [Modular Crypt Format a.k.a. MCF][MCF]) which +works in conjunction with the traits this crate defines. + +## Supported Crates See [RustCrypto/password-hashes] for algorithm implementations which use -these traits. +this crate for interoperability: -[Documentation][docs-link] +- [`argon2`] - Argon2 memory hard key derivation function +- [`pbkdf2`] - Password-Based Key Derivation Function v2 +- [`scrypt`] - scrypt key derivation function ## Minimum Supported Rust Version @@ -61,5 +70,9 @@ dual licensed as above, without any additional terms or conditions. [//]: # (general links) [password hashing algorithms]: https://en.wikipedia.org/wiki/Cryptographic_hash_function#Password_verification -[PHC string format]: https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md +[PHC]: https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md +[MCF]: https://passlib.readthedocs.io/en/stable/modular_crypt_format.html [RustCrypto/password-hashes]: https://github.com/RustCrypto/password-hashes +[`argon2`]: https://docs.rs/argon2 +[`pbkdf2`]: https://docs.rs/pbkdf2 +[`scrypt`]: https://docs.rs/scrypt diff --git a/password-hash/src/ident.rs b/password-hash/src/ident.rs index a97b0ae06..8283385ce 100644 --- a/password-hash/src/ident.rs +++ b/password-hash/src/ident.rs @@ -17,7 +17,7 @@ //! [1]: https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md use crate::{Error, Result}; -use core::{convert::TryFrom, fmt, ops::Deref, str}; +use core::{fmt, ops::Deref, str}; /// Algorithm or parameter identifier. /// @@ -151,7 +151,6 @@ const fn is_char_valid(c: u8) -> bool { #[cfg(test)] mod tests { use super::{Error, Ident}; - use core::convert::TryFrom; // Invalid ident examples const INVALID_EMPTY: &str = ""; diff --git a/password-hash/src/lib.rs b/password-hash/src/lib.rs index 4d8360f03..c59fa2b1f 100644 --- a/password-hash/src/lib.rs +++ b/password-hash/src/lib.rs @@ -1,19 +1,14 @@ -//! This crate defines a set of traits which describe the functionality of -//! [password hashing algorithms]. -//! -//! Provides a `no_std`-friendly implementation of the -//! [Password Hashing Competition (PHC) string format specification][PHC] -//! (a well-defined subset of the [Modular Crypt Format a.k.a. MCF][MCF]) which -//! works in conjunction with the traits this crate defines. -//! -//! # Supported Crates -//! -//! See [RustCrypto/password-hashes] for algorithm implementations which use -//! this crate for interoperability: -//! -//! - [`argon2`] - Argon2 memory hard key derivation function -//! - [`pbkdf2`] - Password-Based Key Derivation Function v2 -//! - [`scrypt`] - scrypt key derivation function +#![no_std] +#![cfg_attr(docsrs, feature(doc_cfg))] +#![doc = include_str!("../README.md")] +#![doc( + html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg", + html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg", + html_root_url = "https://docs.rs/password-hash/0.4.0-pre" +)] +#![forbid(unsafe_code)] +#![warn(missing_docs, rust_2018_idioms, unused_lifetimes)] + //! //! # Usage //! @@ -25,24 +20,6 @@ //! ``` //! //! For more information, please see the documentation for [`PasswordHash`]. -//! -//! [password hashing algorithms]: https://en.wikipedia.org/wiki/Cryptographic_hash_function#Password_verification -//! [PHC]: https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md -//! [MCF]: https://passlib.readthedocs.io/en/stable/modular_crypt_format.html -//! [RustCrypto/password-hashes]: https://github.com/RustCrypto/password-hashes -//! [`argon2`]: https://docs.rs/argon2 -//! [`pbkdf2`]: https://docs.rs/pbkdf2 -//! [`scrypt`]: https://docs.rs/scrypt - -#![no_std] -#![cfg_attr(docsrs, feature(doc_cfg))] -#![doc( - html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg", - html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg", - html_root_url = "https://docs.rs/password-hash/0.4.0-pre" -)] -#![forbid(unsafe_code)] -#![warn(missing_docs, rust_2018_idioms, unused_lifetimes)] #[cfg(feature = "alloc")] extern crate alloc; @@ -74,10 +51,7 @@ pub use crate::{ value::{Decimal, Value}, }; -use core::{ - convert::{TryFrom, TryInto}, - fmt::{self, Debug}, -}; +use core::fmt::{self, Debug}; #[cfg(feature = "alloc")] use alloc::{ diff --git a/password-hash/src/output.rs b/password-hash/src/output.rs index 786e6ae62..c2560ce12 100644 --- a/password-hash/src/output.rs +++ b/password-hash/src/output.rs @@ -1,7 +1,7 @@ //! Outputs from password hashing functions. use crate::{Encoding, Error, Result}; -use core::{cmp::PartialEq, convert::TryFrom, fmt, str::FromStr}; +use core::{cmp::PartialEq, fmt, str::FromStr}; use subtle::{Choice, ConstantTimeEq}; /// Output from password hashing functions, i.e. the "hash" or "digest" diff --git a/password-hash/src/params.rs b/password-hash/src/params.rs index 5dc3c996c..913a55f49 100644 --- a/password-hash/src/params.rs +++ b/password-hash/src/params.rs @@ -6,7 +6,6 @@ use crate::{ Encoding, Error, Ident, Result, }; use core::{ - convert::{TryFrom, TryInto}, fmt::{self, Debug, Write}, iter::FromIterator, str::{self, FromStr}, @@ -325,7 +324,7 @@ mod tests { #[cfg(feature = "alloc")] use alloc::string::ToString; - use core::{convert::TryFrom, str::FromStr}; + use core::str::FromStr; #[test] fn add() { diff --git a/password-hash/src/salt.rs b/password-hash/src/salt.rs index cabd9c281..b5f09f84d 100644 --- a/password-hash/src/salt.rs +++ b/password-hash/src/salt.rs @@ -1,10 +1,7 @@ //! Salt string support. use crate::{Encoding, Error, Result, Value}; -use core::{ - convert::{TryFrom, TryInto}, - fmt, str, -}; +use core::{fmt, str}; use crate::errors::InvalidValue; #[cfg(feature = "rand_core")] diff --git a/password-hash/src/traits.rs b/password-hash/src/traits.rs index 96abccb6a..61e04adda 100644 --- a/password-hash/src/traits.rs +++ b/password-hash/src/traits.rs @@ -1,10 +1,7 @@ //! Trait definitions. use crate::{Decimal, Error, Ident, ParamsString, PasswordHash, Result, Salt}; -use core::{ - convert::{TryFrom, TryInto}, - fmt::Debug, -}; +use core::fmt::Debug; /// Trait for password hashing functions. pub trait PasswordHasher { diff --git a/password-hash/src/value.rs b/password-hash/src/value.rs index 5a453c0f8..acce35cc9 100644 --- a/password-hash/src/value.rs +++ b/password-hash/src/value.rs @@ -15,7 +15,7 @@ use crate::errors::InvalidValue; use crate::{Encoding, Error, Result}; -use core::{convert::TryFrom, fmt, str}; +use core::{fmt, str}; /// Type used to represent decimal (i.e. integer) values. pub type Decimal = u32; @@ -209,7 +209,6 @@ fn is_char_valid(c: char) -> bool { #[cfg(test)] mod tests { use super::{Error, InvalidValue, Value}; - use core::convert::TryFrom; // Invalid value examples const INVALID_CHAR: &str = "x;y"; diff --git a/password-hash/tests/hashing.rs b/password-hash/tests/hashing.rs index 496b4cd00..b88bff86a 100644 --- a/password-hash/tests/hashing.rs +++ b/password-hash/tests/hashing.rs @@ -3,7 +3,6 @@ pub use password_hash::{ Decimal, Error, Ident, Output, ParamsString, PasswordHash, PasswordHasher, Result, Salt, }; -use std::convert::{TryFrom, TryInto}; const ALG: Ident = Ident::new("example"); diff --git a/password-hash/tests/password_hash.rs b/password-hash/tests/password_hash.rs index 107136063..30e4357ed 100644 --- a/password-hash/tests/password_hash.rs +++ b/password-hash/tests/password_hash.rs @@ -4,7 +4,6 @@ //! of the string encoding, and ensures password hashes round trip under each //! of the conditions. -use core::convert::{TryFrom, TryInto}; use password_hash::{Ident, ParamsString, PasswordHash, Salt}; const EXAMPLE_ALGORITHM: Ident = Ident::new("argon2d");