Skip to content

Commit 43fb9b5

Browse files
committed
Hide secret field in Debug impl for Credentials
Technically, this changes behavior of the library, but it is considered that `Debug` output is unstable in general (rust-lang/rust#62794) so you should not be relying on it anyway.
1 parent aca3382 commit 43fb9b5

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

oauth1-request/src/lib.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ pub use signature_method::HmacSha1;
126126
pub use signature_method::Plaintext;
127127

128128
use std::borrow::Borrow;
129-
use std::fmt::Display;
129+
use std::fmt::{self, Debug, Display, Formatter};
130130
use std::num::NonZeroU64;
131131
use std::str;
132132

@@ -160,7 +160,7 @@ pub struct Builder<'a, SM, T = String> {
160160
/// - Client credentials (consumer key and secrets)
161161
/// - Temporary credentials (request token and secret)
162162
/// - Token credentials (access token and secret)
163-
#[derive(Clone, Copy, Debug)]
163+
#[derive(Clone, Copy)]
164164
pub struct Credentials<T = String> {
165165
/// The unique identifier part of the credentials pair.
166166
pub identifier: T,
@@ -398,3 +398,19 @@ impl<T: Borrow<str>> Credentials<T> {
398398
}
399399
}
400400
}
401+
402+
impl<T: Debug> Debug for Credentials<T> {
403+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
404+
struct Dummy;
405+
impl Debug for Dummy {
406+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
407+
f.write_str("<hidden>")
408+
}
409+
}
410+
411+
f.debug_struct("Credentials")
412+
.field("identifier", &self.identifier)
413+
.field("secret", &Dummy)
414+
.finish()
415+
}
416+
}

0 commit comments

Comments
 (0)