pub fn readpassphrase<'a>(
prompt: &CStr,
buf: &'a mut [u8],
flags: RppFlags,
) -> Result<&'a str, Error>Expand description
Reads a passphrase using readpassphrase(3).
This function reads a passphrase of up to buf.len() - 1 bytes. If the entered passphrase is
longer, it will be truncated.
§Security
The passed buffer might contain sensitive data, even if this function returns an error (for
example, if the contents are not valid UTF-8.) It is often considered good practice to zero
this memory after you’re done with it, for example by using zeroize:
use zeroize::Zeroizing;
let mut buf = Zeroizing::new(vec![0u8; PASSWORD_LEN]);
let pass = readpassphrase(c"Pass: ", &mut buf, RppFlags::default())?;Examples found in repository?
examples/inplace.rs (lines 18-22)
13fn main() {
14 #[allow(unused_mut)]
15 let mut buf = vec![0u8; 256];
16 #[cfg(feature = "zeroize")]
17 let mut buf = Zeroizing::new(buf);
18 let password = readpassphrase(
19 c"Password: ",
20 &mut buf,
21 RppFlags::FORCEUPPER | RppFlags::ECHO_ON,
22 )
23 .expect("failed reading passphrase");
24 println!("{password}");
25}