secrets icon indicating copy to clipboard operation
secrets copied to clipboard

How do I handle Strings combined with Secret(Box)?

Open mainrs opened this issue 4 years ago • 1 comments

Hey!

Your examples mostly showcase usage with raw bytes. Could you help me out on working with a String that I want to securely store inside one of the Secret variants? The String is read from the tty (it's a user-entered password).

The SecretBox documentation showcases an example where some bytes are moved into SecretVec by using the from method. Is that currently the only way to accomplish this?

Thanks for helping me out!

mainrs avatar Apr 03 '21 16:04 mainrs

std::io::Stdin implments the Read trait, so you can read raw bytes from it into a provided buffer (such as that returned by secret.borrow_mut()).

That's not the most useful thing right now since generally you want to read lines (which go into a String). I can look and see what I can do about providing a way to borrow the internal contents directly as a string.

stouset avatar Apr 05 '21 17:04 stouset