Skip to content

Commit 7fb782a

Browse files
authored
password-hash: Add Output::with_encoding method (RustCrypto#1657)
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.
1 parent bc109d0 commit 7fb782a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

password-hash/src/output.rs

+5
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ impl Output {
182182
self.encoding
183183
}
184184

185+
/// Creates a copy of this [`Output`] with the specified [`Encoding`].
186+
pub fn with_encoding(&self, encoding: Encoding) -> Self {
187+
Self { encoding, ..*self }
188+
}
189+
185190
/// Get the length of the output value as a byte slice.
186191
pub fn len(&self) -> usize {
187192
usize::from(self.length)

0 commit comments

Comments
 (0)