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

Deserialize SecretString #1219

Closed
jssblck opened this issue Sep 19, 2024 · 0 comments · Fixed by #1220
Closed

Deserialize SecretString #1219

jssblck opened this issue Sep 19, 2024 · 0 comments · Fixed by #1220

Comments

@jssblck
Copy link

jssblck commented Sep 19, 2024

It's very unclear how to do this after the latest release (secrecy 0.10.1).

This works:

#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct Auth {
    username: String,
    password: SecretString,
}

But this fails:

#[derive(Debug, Clone, serde::Deserialize)]
#[non_exhaustive]
pub struct Auth {
    username: String,
    password: SecretString,
}

The error message:

the trait bound `str: std::clone::Clone` is not satisfied
the trait `std::clone::Clone` is implemented for `std::string::String`
required for `secrecy::SecretBox<str>` to implement `maven::_::_serde::Deserialize<'_>`rustc[Click for full compiler diagnostic](... snip ...)
de.rs(25, 8): required by a bound in `maven::_::_serde::__private::de::missing_field`

In my use case, the secret is transmitted across the network so I really don't care about leaking on the stack vs the heap. What I really want is to just avoid having this value accidentally emitted in logs, so I just want it to be deserialized directly upon receipt and stored from there.

Is this library still a good fit for this use case? If so, how can I make this work?

tony-iqlusion added a commit that referenced this issue Sep 19, 2024
It needs a special impl since `SecretBox<str>` (which `SecretString` is
a type alias for) doesn't meet the `Clone` bound (i.e. `str` doesn't
impl `Clone`).

Closes #1219
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant