Skip to content

Commit

Permalink
password-hash: Add Output::with_encoding method (#1657)
Browse files Browse the repository at this point in the history
Allows `Display`/`Debug` printing `Output` with a specific `Encoding`
without needing to go through `encode`/`b64_encode`, if e.g. it was
created using `init_with`.

Maybe a version of `init_with` that allows specifying an encoding
(similar to `new_with_encoding`) would be better, I'm not sure. This is
a smaller, more general change.
  • Loading branch information
LunarLambda authored Sep 5, 2024
1 parent bc109d0 commit 7fb782a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions password-hash/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ impl Output {
self.encoding
}

/// Creates a copy of this [`Output`] with the specified [`Encoding`].
pub fn with_encoding(&self, encoding: Encoding) -> Self {
Self { encoding, ..*self }
}

/// Get the length of the output value as a byte slice.
pub fn len(&self) -> usize {
usize::from(self.length)
Expand Down

0 comments on commit 7fb782a

Please sign in to comment.