Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Debug on Decoding/EncodingKey while redacting sensitive fields #406

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 16 additions & 1 deletion src/decoding.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::{Debug, Formatter};

use base64::{engine::general_purpose::STANDARD, Engine};
use serde::de::DeserializeOwned;

Expand Down Expand Up @@ -47,9 +49,22 @@ pub(crate) enum DecodingKeyKind {
RsaModulusExponent { n: Vec<u8>, e: Vec<u8> },
}

impl Debug for DecodingKeyKind {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::SecretOrDer(_) => f.debug_tuple("SecretOrDer").field(&"[redacted]").finish(),
Self::RsaModulusExponent { .. } => f
.debug_struct("RsaModulusExponent")
.field("n", &"[redacted]")
.field("e", &"[redacted]")
.finish(),
}
}
}

/// All the different kind of keys we can use to decode a JWT.
/// This key can be re-used so make sure you only initialize it once if you can for better performance.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct DecodingKey {
pub(crate) family: AlgorithmFamily,
pub(crate) kind: DecodingKeyKind,
Expand Down
11 changes: 11 additions & 0 deletions src/encoding.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::{Debug, Formatter};

use base64::{engine::general_purpose::STANDARD, Engine};
use serde::ser::Serialize;

Expand Down Expand Up @@ -96,6 +98,15 @@ impl EncodingKey {
}
}

impl Debug for EncodingKey {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("EncodingKey")
.field("family", &self.family)
.field("content", &"[redacted]")
.finish()
}
}

/// Encode the header and claims given and sign the payload using the algorithm from the header and the key.
/// If the algorithm given is RSA or EC, the key needs to be in the PEM format.
///
Expand Down
Loading