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

Into version for SecretString expose_secret #1182

Open
tisonkun opened this issue Apr 26, 2024 · 3 comments
Open

Into version for SecretString expose_secret #1182

tisonkun opened this issue Apr 26, 2024 · 3 comments

Comments

@tisonkun
Copy link

I found that we have a rewrite also. When do we release 0.9 for secrecy?

For this issue, I found:

impl<S> ExposeSecret<S> for Secret<S>
where
    S: Zeroize,
{
    fn expose_secret(&self) -> &S {
        &self.inner_secret
    }
}

But perhaps I'd like to move the inner secret in some case, and thus an into version can help to avoid copy.

@tony-iqlusion
Copy link
Member

into version can help to avoid copy

Since Rust doesn't have placement by return, an API which returns a value will always make a copy

@tisonkun
Copy link
Author

tisonkun commented Oct 30, 2024

@tony-iqlusion but copy the pointer and length of a string (into_inner(self) -> String) is still different to copy the whole payload (self.expose_secret().to_string())?

@tony-iqlusion
Copy link
Member

It might be okay for select heap-backed types, namely SecretString and SecretSlice, though it seems a little odd given the goal of the crate of encapsulating and owning/protecting secrets to hand off ownership

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

No branches or pull requests

2 participants