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
8 changes: 7 additions & 1 deletion sha-crypt/src/mcf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ pub struct ShaCrypt {
}

impl ShaCrypt {
/// SHA-crypt configured with SHA-256 as the default.
pub const SHA256: Self = Self::new(Algorithm::Sha256Crypt, Params::RECOMMENDED);

/// SHA-crypt configured with SHA-512 as the default.
pub const SHA512: Self = Self::new(Algorithm::Sha512Crypt, Params::RECOMMENDED);

/// Create a new password hasher with customized algorithm and params.
pub fn new(algorithm: Algorithm, params: Params) -> Self {
pub const fn new(algorithm: Algorithm, params: Params) -> Self {
Self { algorithm, params }
}
}
Expand Down
13 changes: 8 additions & 5 deletions sha-crypt/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ pub struct Params {
}

impl Params {
/// Default number of rounds.
pub const ROUNDS_DEFAULT: u32 = 5_000;
/// Recommended parameters.
pub const RECOMMENDED: Self = Self {
rounds: Self::RECOMMENDED_ROUNDS,
};

/// Recommended number of rounds.
pub const RECOMMENDED_ROUNDS: u32 = 5_000;

/// Minimum number of rounds allowed.
pub const ROUNDS_MIN: u32 = 1_000;
Expand All @@ -38,9 +43,7 @@ impl Params {

impl Default for Params {
fn default() -> Self {
Params {
rounds: Self::ROUNDS_DEFAULT,
}
Params::RECOMMENDED
}
}

Expand Down