secrecy: how should one use `SecretBytesMut`?
fjarri opened this issue · comments
Bogdan Opanchuk commented
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?
Jim Chng commented
You might want to build the bytes first before moving it into the new
constructor since the constructor consumes the value.
Bogdan Opanchuk commented
Thanks for reminding me, this will be closed (or rather invalidated) by #1140.