pub struct IntoError(/* private fields */);Expand description
An Error from readpassphrase_into containing the passed buffer.
The buffer is accessible via IntoError::into_bytes, and the Error via
IntoError::error.
If into_bytes is not called, the buffer is automatically zeroed on drop.
Implementations§
Source§impl IntoError
impl IntoError
Sourcepub fn error(&self) -> &Error
pub fn error(&self) -> &Error
Return the Error corresponding to this.
Examples found in repository?
examples/owned.rs (line 18)
4fn main() -> Result<(), Error> {
5 let mut buf = Zeroizing::new(Some(vec![0u8; PASSWORD_LEN]));
6 let pass = Zeroizing::new(
7 readpassphrase(c"Password: ", buf.as_deref_mut().unwrap(), Flags::ECHO_ON)?.to_string(),
8 );
9 let mut buf = buf.take();
10 loop {
11 buf = Some(
12 match readpassphrase_into(c"Confirmation: ", buf.take().unwrap(), Flags::REQUIRE_TTY) {
13 Ok(mut s) if *pass == s => {
14 s.zeroize();
15 break;
16 }
17 Ok(s) => s.into_bytes(),
18 Err(e) => match e.error() {
19 Error::Io(_) => return Err(e.into()),
20 Error::Utf8(_) => {
21 eprintln!("decode error: {e}");
22 e.into_bytes()
23 }
24 },
25 },
26 );
27 }
28 Ok(())
29}Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Returns the buffer that was passed to readpassphrase_into.
§Security
The returned buffer may contain sensitive data in its spare capacity, even if the
buffer’s length is zero. It is the caller’s responsibility to zero it as soon as possible
if needed, e.g. using Zeroize:
let mut buf = err.into_bytes();
// ...
buf.zeroize();Examples found in repository?
examples/owned.rs (line 22)
4fn main() -> Result<(), Error> {
5 let mut buf = Zeroizing::new(Some(vec![0u8; PASSWORD_LEN]));
6 let pass = Zeroizing::new(
7 readpassphrase(c"Password: ", buf.as_deref_mut().unwrap(), Flags::ECHO_ON)?.to_string(),
8 );
9 let mut buf = buf.take();
10 loop {
11 buf = Some(
12 match readpassphrase_into(c"Confirmation: ", buf.take().unwrap(), Flags::REQUIRE_TTY) {
13 Ok(mut s) if *pass == s => {
14 s.zeroize();
15 break;
16 }
17 Ok(s) => s.into_bytes(),
18 Err(e) => match e.error() {
19 Error::Io(_) => return Err(e.into()),
20 Error::Utf8(_) => {
21 eprintln!("decode error: {e}");
22 e.into_bytes()
23 }
24 },
25 },
26 );
27 }
28 Ok(())
29}Trait Implementations§
Source§impl Error for IntoError
impl Error for IntoError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for IntoError
impl !RefUnwindSafe for IntoError
impl Send for IntoError
impl Sync for IntoError
impl Unpin for IntoError
impl !UnwindSafe for IntoError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more