Skip to content

Commit 9a459c3

Browse files
authored
Remove phc::Ident lifetime (#754)
Companion PR to RustCrypto/traits#2107
1 parent 8f8d753 commit 9a459c3

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

argon2/src/algorithm.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ use password_hash::phc::Ident;
1111

1212
/// Argon2d algorithm identifier
1313
#[cfg(feature = "password-hash")]
14-
pub const ARGON2D_IDENT: Ident<'_> = Ident::new_unwrap("argon2d");
14+
pub const ARGON2D_IDENT: Ident = Ident::new_unwrap("argon2d");
1515

1616
/// Argon2i algorithm identifier
1717
#[cfg(feature = "password-hash")]
18-
pub const ARGON2I_IDENT: Ident<'_> = Ident::new_unwrap("argon2i");
18+
pub const ARGON2I_IDENT: Ident = Ident::new_unwrap("argon2i");
1919

2020
/// Argon2id algorithm identifier
2121
#[cfg(feature = "password-hash")]
22-
pub const ARGON2ID_IDENT: Ident<'_> = Ident::new_unwrap("argon2id");
22+
pub const ARGON2ID_IDENT: Ident = Ident::new_unwrap("argon2id");
2323

2424
/// Argon2 primitive type: variants of the algorithm.
2525
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Default, Ord)]
@@ -65,7 +65,7 @@ impl Algorithm {
6565

6666
/// Get the [`Ident`] that corresponds to this Argon2 [`Algorithm`].
6767
#[cfg(feature = "password-hash")]
68-
pub const fn ident(&self) -> Ident<'static> {
68+
pub const fn ident(&self) -> Ident {
6969
match self {
7070
Algorithm::Argon2d => ARGON2D_IDENT,
7171
Algorithm::Argon2i => ARGON2I_IDENT,
@@ -105,8 +105,8 @@ impl FromStr for Algorithm {
105105
}
106106

107107
#[cfg(feature = "password-hash")]
108-
impl From<Algorithm> for Ident<'static> {
109-
fn from(alg: Algorithm) -> Ident<'static> {
108+
impl From<Algorithm> for Ident {
109+
fn from(alg: Algorithm) -> Ident {
110110
alg.ident()
111111
}
112112
}

balloon-hash/src/algorithm.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ pub enum Algorithm {
2626
impl Algorithm {
2727
/// Balloon algorithm identifier
2828
#[cfg(feature = "password-hash")]
29-
pub const BALLOON_IDENT: Ident<'static> = Ident::new_unwrap("balloon");
29+
pub const BALLOON_IDENT: Ident = Ident::new_unwrap("balloon");
3030

3131
/// BalloonM algorithm identifier
3232
#[cfg(feature = "password-hash")]
33-
pub const BALLOON_M_IDENT: Ident<'static> = Ident::new_unwrap("balloon-m");
33+
pub const BALLOON_M_IDENT: Ident = Ident::new_unwrap("balloon-m");
3434

3535
/// Parse an [`Algorithm`] from the provided string.
3636
pub fn new(id: impl AsRef<str>) -> Result<Self> {
@@ -47,7 +47,7 @@ impl Algorithm {
4747

4848
/// Get the [`Ident`] that corresponds to this Balloon [`Algorithm`].
4949
#[cfg(feature = "password-hash")]
50-
pub fn ident(&self) -> Ident<'static> {
50+
pub fn ident(&self) -> Ident {
5151
match self {
5252
Algorithm::Balloon => Self::BALLOON_IDENT,
5353
Algorithm::BalloonM => Self::BALLOON_M_IDENT,
@@ -80,8 +80,8 @@ impl FromStr for Algorithm {
8080
}
8181

8282
#[cfg(feature = "password-hash")]
83-
impl From<Algorithm> for Ident<'static> {
84-
fn from(alg: Algorithm) -> Ident<'static> {
83+
impl From<Algorithm> for Ident {
84+
fn from(alg: Algorithm) -> Ident {
8585
alg.ident()
8686
}
8787
}

password-auth/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub fn is_hash_obsolete(hash: &str) -> Result<bool, ParseError> {
120120
|| hash.params != default_params_string::<scrypt::Params>());
121121

122122
#[cfg(feature = "pbkdf2")]
123-
return Ok(hash.algorithm != pbkdf2::Algorithm::default().ident()
123+
return Ok(hash.algorithm != *pbkdf2::Algorithm::default().ident()
124124
|| hash.params != default_params_string::<pbkdf2::Params>());
125125

126126
Ok(true)

pbkdf2/src/simple.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl CustomizedPasswordHasher for Pbkdf2 {
5858
})?;
5959

6060
Ok(PasswordHash {
61-
algorithm: algorithm.ident(),
61+
algorithm: *algorithm.ident(),
6262
version: None,
6363
params: params.try_into()?,
6464
salt: Some(salt),
@@ -105,26 +105,26 @@ impl Default for Algorithm {
105105
impl Algorithm {
106106
/// PBKDF2 (SHA-1) algorithm identifier
107107
#[cfg(feature = "sha1")]
108-
pub const PBKDF2_SHA1_IDENT: Ident<'static> = Ident::new_unwrap("pbkdf2");
108+
pub const PBKDF2_SHA1_IDENT: Ident = Ident::new_unwrap("pbkdf2");
109109

110110
/// PBKDF2 (SHA-256) algorithm identifier
111-
pub const PBKDF2_SHA256_IDENT: Ident<'static> = Ident::new_unwrap("pbkdf2-sha256");
111+
pub const PBKDF2_SHA256_IDENT: Ident = Ident::new_unwrap("pbkdf2-sha256");
112112

113113
/// PBKDF2 (SHA-512) algorithm identifier
114-
pub const PBKDF2_SHA512_IDENT: Ident<'static> = Ident::new_unwrap("pbkdf2-sha512");
114+
pub const PBKDF2_SHA512_IDENT: Ident = Ident::new_unwrap("pbkdf2-sha512");
115115

116116
/// Parse an [`Algorithm`] from the provided string.
117117
pub fn new(id: impl AsRef<str>) -> Result<Self> {
118118
id.as_ref().parse()
119119
}
120120

121121
/// Get the [`Ident`] that corresponds to this PBKDF2 [`Algorithm`].
122-
pub fn ident(&self) -> Ident<'static> {
122+
pub fn ident(&self) -> &'static Ident {
123123
match self {
124124
#[cfg(feature = "sha1")]
125-
Algorithm::Pbkdf2Sha1 => Self::PBKDF2_SHA1_IDENT,
126-
Algorithm::Pbkdf2Sha256 => Self::PBKDF2_SHA256_IDENT,
127-
Algorithm::Pbkdf2Sha512 => Self::PBKDF2_SHA512_IDENT,
125+
Algorithm::Pbkdf2Sha1 => &Self::PBKDF2_SHA1_IDENT,
126+
Algorithm::Pbkdf2Sha256 => &Self::PBKDF2_SHA256_IDENT,
127+
Algorithm::Pbkdf2Sha512 => &Self::PBKDF2_SHA512_IDENT,
128128
}
129129
}
130130

@@ -154,9 +154,9 @@ impl FromStr for Algorithm {
154154
}
155155
}
156156

157-
impl From<Algorithm> for Ident<'static> {
158-
fn from(alg: Algorithm) -> Ident<'static> {
159-
alg.ident()
157+
impl From<Algorithm> for Ident {
158+
fn from(alg: Algorithm) -> Ident {
159+
*alg.ident()
160160
}
161161
}
162162

pbkdf2/tests/simple.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn hash_with_default_algorithm() {
2929
.hash_password_customized(PASSWORD.as_bytes(), None, None, params, salt)
3030
.unwrap();
3131

32-
assert_eq!(hash.algorithm, Algorithm::Pbkdf2Sha256.ident());
32+
assert_eq!(hash.algorithm, *Algorithm::Pbkdf2Sha256.ident());
3333
assert_eq!(hash.salt.unwrap().as_str(), SALT_B64);
3434
assert_eq!(Params::try_from(&hash).unwrap(), params);
3535

0 commit comments

Comments
 (0)