readpassphrase-3
This crate endeavors to expose a thin wrapper around the OpenBSD readpassphrase(3) function. Three interfaces are exposed:
readpassphrase, which allocates and returns its own fixed-size buffer for the passphrase; andreadpassphrase_buf, which takes a preallocated buffer that it consumes and returns as the outputString.readpassphrase_inplace, which takes a buffer as a byte slice and returns a&strin that buffer.
These may be customized using RppFlags, which expose the original API’s flags.
This library uses a couple of third-party dependencies: RppFlags is implemented via the bitflags library, and memory zeroing is by default done via zeroize. To try to reduce churn in this library itself, and dependencies on multiple versions of libraries in dependent packages, we do not lock the versions of these dependencies; it is recommended that you vet their current versions yourself to guard against software supply chain attacks. If you would rather not do that, consider instead using the excellent rpassword crate, which vendors its own dependencies.
NFAQ
I’m getting a “mismatched types” error!
That’s not a question, but it’s okay. You are probably passing a Rust &str as the prompt argument. To avoid needing to take a dynamically allocated string or make a copy of the prompt on every call, this library takes a &CStr (i.e. a null-terminated span of characters) as its prompt argument.
If you’re passing a literal string, you can just prepend c to your string:
let _ = readpassphrase?;
// ^
// |
// like this
Why is this named readpassphrase-3?
There is already an unmaintained readpassphrase crate that was not to my liking. Rather than try to invent a new name for this standard C function, I decided to pick a number. The number I picked, 3, corresponds to the “library calls” man section, in which readpassphrase’s man page is located.