[−][src]Struct nitrokey::PasswordSafe
A password safe on a Nitrokey device.
The password safe stores a tuple consisting of a name, a login and a password on a slot. The
number of available slots is SLOT_COUNT
. The slots are addressed starting with zero. To
retrieve a password safe from a Nitrokey device, use the get_password_safe
method from
the GetPasswordSafe
trait. Note that the device must live at least as long as the
password safe.
Once the password safe has been unlocked, it can be accessed without a password. Therefore it
is mandatory to call lock
on the corresponding device after the password store is used.
As this command may have side effects on the Nitrokey Storage, it cannot be called
automatically once the password safe is destroyed.
Examples
Open a password safe and access a password:
use nitrokey::{Device, GetPasswordSafe, PasswordSafe}; fn use_password_safe(pws: &PasswordSafe) -> Result<(), CommandError> { let name = pws.get_slot_name(0)?; let login = pws.get_slot_login(0)?; let password = pws.get_slot_login(0)?; println!("Credentials for {}: login {}, password {}", name, login, password); Ok(()) } let device = nitrokey::connect()?; let pws = device.get_password_safe("123456")?; use_password_safe(&pws); device.lock()?;
Methods
impl<'a> PasswordSafe<'a>
[src]
pub fn get_slot_status(&self) -> Result<[bool; 16], CommandError>
[src]
Returns the status of all password slots.
The status indicates whether a slot is programmed or not.
Example
use nitrokey::{GetPasswordSafe, SLOT_COUNT}; let device = nitrokey::connect()?; let pws = device.get_password_safe("123456")?; pws.get_slot_status()?.iter().enumerate().for_each(|(slot, programmed)| { let status = match *programmed { true => "programmed", false => "not programmed", }; println!("Slot {}: {}", slot, status); });
pub fn get_slot_name(&self, slot: u8) -> Result<String, CommandError>
[src]
Returns the name of the given slot (if it is programmed).
This method also returns a SlotNotProgrammed
error if the name is empty.
Errors
InvalidSlot
if the given slot is out of rangeSlotNotProgrammed
if the slot is not programmed
Example
use nitrokey::GetPasswordSafe; let device = nitrokey::connect()?; match device.get_password_safe("123456") { Ok(pws) => { let name = pws.get_slot_name(0)?; let login = pws.get_slot_login(0)?; let password = pws.get_slot_login(0)?; println!("Credentials for {}: login {}, password {}", name, login, password); }, Err(err) => println!("Could not open the password safe: {}", err), };
pub fn get_slot_login(&self, slot: u8) -> Result<String, CommandError>
[src]
Returns the login for the given slot (if it is programmed).
This method also returns a SlotNotProgrammed
error if the login is empty.
Errors
InvalidSlot
if the given slot is out of rangeSlotNotProgrammed
if the slot is not programmed
Example
use nitrokey::GetPasswordSafe; let device = nitrokey::connect()?; let pws = device.get_password_safe("123456")?; let name = pws.get_slot_name(0)?; let login = pws.get_slot_login(0)?; let password = pws.get_slot_login(0)?; println!("Credentials for {}: login {}, password {}", name, login, password);
pub fn get_slot_password(&self, slot: u8) -> Result<String, CommandError>
[src]
Returns the password for the given slot (if it is programmed).
This method also returns a SlotNotProgrammed
error if the password is empty.
Errors
InvalidSlot
if the given slot is out of rangeSlotNotProgrammed
if the slot is not programmed
Example
use nitrokey::GetPasswordSafe; let device = nitrokey::connect()?; let pws = device.get_password_safe("123456")?; let name = pws.get_slot_name(0)?; let login = pws.get_slot_login(0)?; let password = pws.get_slot_login(0)?; println!("Credentials for {}: login {}, password {}", name, login, password);
pub fn write_slot(
&self,
slot: u8,
name: &str,
login: &str,
password: &str
) -> Result<(), CommandError>
[src]
&self,
slot: u8,
name: &str,
login: &str,
password: &str
) -> Result<(), CommandError>
Writes the given slot with the given name, login and password.
Errors
InvalidSlot
if the given slot is out of rangeInvalidString
if the provided token ID contains a null byte
Example
use nitrokey::GetPasswordSafe; let device = nitrokey::connect()?; let pws = device.get_password_safe("123456")?; let name = pws.get_slot_name(0)?; let login = pws.get_slot_login(0)?; let password = pws.get_slot_login(0)?; println!("Credentials for {}: login {}, password {}", name, login, password);
pub fn erase_slot(&self, slot: u8) -> Result<(), CommandError>
[src]
Erases the given slot. Erasing clears the stored name, login and password (if the slot was programmed).
Errors
InvalidSlot
if the given slot is out of range
Example
use nitrokey::GetPasswordSafe; let device = nitrokey::connect()?; let pws = device.get_password_safe("123456")?; match pws.erase_slot(0) { Ok(()) => println!("Erased slot 0."), Err(err) => println!("Could not erase slot 0: {}", err), };
Trait Implementations
impl<'a> Drop for PasswordSafe<'a>
[src]
Auto Trait Implementations
impl<'a> !RefUnwindSafe for PasswordSafe<'a>
impl<'a> !Send for PasswordSafe<'a>
impl<'a> !Sync for PasswordSafe<'a>
impl<'a> Unpin for PasswordSafe<'a>
impl<'a> !UnwindSafe for PasswordSafe<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,