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

secrecy: how should one use SecretBytesMut? #1066

Open
fjarri opened this issue Oct 8, 2022 · 2 comments
Open

secrecy: how should one use SecretBytesMut? #1066

fjarri opened this issue Oct 8, 2022 · 2 comments

Comments

@fjarri
Copy link
Contributor

fjarri commented Oct 8, 2022

Perhaps I do not understand something, but how can one use the current API to actually mutate the insides of the secret? In my case, I want to create a secret random seed, so I write

let key = SecretBytesMut::new(BytesMut::zeroed(32));
OsRng.fill_bytes(key.expose_secret().as_mut());

Which results in a "cannot borrow as mutable" for key.expose_secret().as_mut(). Which I understand - expose_secret() returns an immutable reference - but how to get a mutable access to the bytes then?

@jymchng
Copy link

jymchng commented Jul 2, 2023

You might want to build the bytes first before moving it into the new constructor since the constructor consumes the value.

@fjarri
Copy link
Contributor Author

fjarri commented Jul 2, 2023

Thanks for reminding me, this will be closed (or rather invalidated) by #1140.

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