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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mcf/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mcf"
version = "0.2.0"
version = "0.6.0-pre"
authors = ["RustCrypto Developers"]
edition = "2024"
rust-version = "1.85"
Expand Down
23 changes: 19 additions & 4 deletions mcf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ mod allocating {
Ok(Self(s))
}

/// Borrow the contents of this password hash as a [`PasswordHashRef`].
///
/// Similar conversions can be performed using [`AsRef`], [`Borrow`], and [`Deref`], however
/// this one is useful when the return type may be ambiguous and avoiding potential
/// inference bugs is preferable.
pub fn as_password_hash_ref(&self) -> &PasswordHashRef {
PasswordHashRef::new_unchecked(&self.0)
}

/// Create an [`PasswordHash`] from an identifier.
///
/// # Returns
Expand Down Expand Up @@ -207,21 +216,21 @@ mod allocating {

impl AsRef<PasswordHashRef> for PasswordHash {
fn as_ref(&self) -> &PasswordHashRef {
PasswordHashRef::new_unchecked(&self.0)
self.as_password_hash_ref()
}
}

impl Borrow<PasswordHashRef> for PasswordHash {
fn borrow(&self) -> &PasswordHashRef {
self.as_ref()
self.as_password_hash_ref()
}
}

impl Deref for PasswordHash {
type Target = PasswordHashRef;

fn deref(&self) -> &PasswordHashRef {
self.as_ref()
self.as_password_hash_ref()
}
}

Expand All @@ -231,6 +240,12 @@ mod allocating {
}
}

impl From<&PasswordHash> for String {
fn from(hash: &PasswordHash) -> Self {
hash.0.clone()
}
}

impl FromStr for PasswordHash {
type Err = Error;

Expand Down Expand Up @@ -267,7 +282,7 @@ mod allocating {

impl<'a> From<&'a PasswordHash> for &'a PasswordHashRef {
fn from(hash: &'a PasswordHash) -> &'a PasswordHashRef {
hash.as_ref()
hash.as_password_hash_ref()
}
}

Expand Down