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 SecretType::into_secret #272

Merged
merged 1 commit into from
May 7, 2024
Merged
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
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]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeating the same docstring, as it is rather general.

///
/// # 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());
Copy link
Contributor Author

@IvanUkhov IvanUkhov May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to use a method present exclusively in the owned value.

}

#[test]
fn test_secret_redaction() {
Expand Down
Loading