Skip to content

Commit

Permalink
Hide secret field in Debug impl for Credentials
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tesaguri committed Mar 12, 2020
1 parent aca3382 commit 43fb9b5
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions oauth1-request/src/lib.rs
Expand Up @@ -126,7 +126,7 @@ pub use signature_method::HmacSha1;
pub use signature_method::Plaintext;

use std::borrow::Borrow;
use std::fmt::Display;
use std::fmt::{self, Debug, Display, Formatter};
use std::num::NonZeroU64;
use std::str;

Expand Down Expand Up @@ -160,7 +160,7 @@ pub struct Builder<'a, SM, T = String> {
/// - Client credentials (consumer key and secrets)
/// - Temporary credentials (request token and secret)
/// - Token credentials (access token and secret)
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy)]
pub struct Credentials<T = String> {
/// The unique identifier part of the credentials pair.
pub identifier: T,
Expand Down Expand Up @@ -398,3 +398,19 @@ impl<T: Borrow<str>> Credentials<T> {
}
}
}

impl<T: Debug> Debug for Credentials<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
struct Dummy;
impl Debug for Dummy {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str("<hidden>")
}
}

f.debug_struct("Credentials")
.field("identifier", &self.identifier)
.field("secret", &Dummy)
.finish()
}
}

0 comments on commit 43fb9b5

Please sign in to comment.