Skip to content

Commit 90cb9fb

Browse files
authored
phc: deprecate PasswordHashString (#2112)
It was originally added because `PasswordHash` had a lifetime, so it provided an owned alternative. But now `PasswordHash` is fully owned (and also fully stack allocated, so no `alloc` dependency). The suggested replacements are using `PasswordHash` if the goal was to have an owned password hash type, or `String` if the goal is to have a string representation of a PHC hash.
1 parent 1e7caeb commit 90cb9fb

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

phc/src/lib.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,10 @@ impl PasswordHash {
174174
})
175175
}
176176

177-
/// Serialize this [`PasswordHash`] as a [`PasswordHashString`].
177+
/// DEPRECATED: serialize this [`PasswordHash`] as a [`PasswordHashString`].
178+
#[allow(deprecated)]
178179
#[cfg(feature = "alloc")]
180+
#[deprecated(since = "0.3.0", note = "Use `PasswordHash` or `String` instead")]
179181
pub fn serialize(&self) -> PasswordHashString {
180182
self.into()
181183
}
@@ -221,11 +223,15 @@ impl fmt::Display for PasswordHash {
221223
}
222224
}
223225

224-
/// Serialized [`PasswordHash`].
226+
/// DEPRECATED: serialized [`PasswordHash`].
225227
///
226228
/// This type contains a serialized password hash string which is ensured to
227229
/// parse successfully.
228-
// TODO(tarcieri): cached parsed representations? or at least structural data
230+
///
231+
/// This was originally available to provide an owned representation for a password hash, but now
232+
/// that [`PasswordHash`] is fully owned, it can be used instead, or `String` to store a
233+
/// serialized PHC string.
234+
#[deprecated(since = "0.3.0", note = "Use `PasswordHash` or `String` instead")]
229235
#[cfg(feature = "alloc")]
230236
#[derive(Clone, Debug, Eq, PartialEq)]
231237
pub struct PasswordHashString {
@@ -234,7 +240,7 @@ pub struct PasswordHashString {
234240
}
235241

236242
#[cfg(feature = "alloc")]
237-
#[allow(clippy::len_without_is_empty)]
243+
#[allow(clippy::len_without_is_empty, deprecated)]
238244
impl PasswordHashString {
239245
/// Parse a password hash from a string in the PHC string format.
240246
pub fn new(s: &str) -> Result<Self> {
@@ -287,20 +293,23 @@ impl PasswordHashString {
287293
}
288294
}
289295

296+
#[allow(deprecated)]
290297
#[cfg(feature = "alloc")]
291298
impl AsRef<str> for PasswordHashString {
292299
fn as_ref(&self) -> &str {
293300
self.as_str()
294301
}
295302
}
296303

304+
#[allow(deprecated)]
297305
#[cfg(feature = "alloc")]
298306
impl From<PasswordHash> for PasswordHashString {
299307
fn from(hash: PasswordHash) -> PasswordHashString {
300308
PasswordHashString::from(&hash)
301309
}
302310
}
303311

312+
#[allow(deprecated)]
304313
#[cfg(feature = "alloc")]
305314
impl From<&PasswordHash> for PasswordHashString {
306315
fn from(hash: &PasswordHash) -> PasswordHashString {
@@ -310,6 +319,7 @@ impl From<&PasswordHash> for PasswordHashString {
310319
}
311320
}
312321

322+
#[allow(deprecated)]
313323
#[cfg(feature = "alloc")]
314324
impl FromStr for PasswordHashString {
315325
type Err = Error;
@@ -319,6 +329,7 @@ impl FromStr for PasswordHashString {
319329
}
320330
}
321331

332+
#[allow(deprecated)]
322333
#[cfg(feature = "alloc")]
323334
impl fmt::Display for PasswordHashString {
324335
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

0 commit comments

Comments
 (0)