iqlusioninc / crates

A collection of open source Rust crates from iqlusion

Home Page:https://www.iqlusion.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

secrecy: how should one use `SecretBytesMut`?

fjarri opened this issue · comments

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?

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

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