Skip to content

Commit

Permalink
Implement SecretType::into_secret (#272)
Browse files Browse the repository at this point in the history
Resolves #271.
  • Loading branch information
IvanUkhov authored May 7, 2024
1 parent 3174290 commit daf4db6
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,20 @@ macro_rules! new_secret_type {
pub fn new(s: $type) -> Self {
$name(s)
}

#[doc = $secret_doc]
///
/// # Security Warning
///
/// Leaking this value may compromise the security of the OAuth2 flow.
pub fn secret(&self) -> &$type { &self.0 }

#[doc = $secret_doc]
///
/// # Security Warning
///
/// Leaking this value may compromise the security of the OAuth2 flow.
pub fn into_secret(self) -> $type { self.0 }
}
impl Debug for $name {
fn fmt(&self, f: &mut Formatter) -> Result<(), FormatterError> {
Expand Down Expand Up @@ -606,7 +614,13 @@ new_secret_type![

#[cfg(test)]
mod tests {
use crate::{ClientSecret, PkceCodeChallenge, PkceCodeVerifier};
use crate::{ClientSecret, CsrfToken, PkceCodeChallenge, PkceCodeVerifier};

#[test]
fn test_secret_conversion() {
let secret = CsrfToken::new("top_secret".into());
assert_eq!(secret.into_secret().into_boxed_str(), "top_secret".into());
}

#[test]
fn test_secret_redaction() {
Expand Down

0 comments on commit daf4db6

Please sign in to comment.