[−][src]Trait nitrokey::Authenticate
Provides methods to authenticate as a user or as an admin using a PIN. The authenticated methods will consume the current device instance. On success, they return the authenticated device. Otherwise, they return the current unauthenticated device and the error code.
Required methods
fn authenticate_user(
self,
password: &str
) -> Result<User<'a, Self>, (Self, Error)> where
Self: Device<'a> + Sized,
self,
password: &str
) -> Result<User<'a, Self>, (Self, Error)> where
Self: Device<'a> + Sized,
Performs user authentication. This method consumes the device. If successful, an authenticated device is returned. Otherwise, the current unauthenticated device and the error are returned.
This method generates a random temporary password that is used for all operations that require user access.
Errors
InvalidString
if the provided user password contains a null byteRngError
if the generation of the temporary password failedWrongPassword
if the provided user password is wrong
Example
use nitrokey::{Authenticate, DeviceWrapper, User}; fn perform_user_task<'a>(device: &User<'a, DeviceWrapper<'a>>) {} fn perform_other_task(device: &DeviceWrapper) {} let mut manager = nitrokey::take()?; let device = manager.connect()?; let device = match device.authenticate_user("123456") { Ok(user) => { perform_user_task(&user); user.device() }, Err((device, err)) => { eprintln!("Could not authenticate as user: {}", err); device }, }; perform_other_task(&device);
fn authenticate_admin(
self,
password: &str
) -> Result<Admin<'a, Self>, (Self, Error)> where
Self: Device<'a> + Sized,
self,
password: &str
) -> Result<Admin<'a, Self>, (Self, Error)> where
Self: Device<'a> + Sized,
Performs admin authentication. This method consumes the device. If successful, an authenticated device is returned. Otherwise, the current unauthenticated device and the error are returned.
This method generates a random temporary password that is used for all operations that require admin access.
Errors
InvalidString
if the provided admin password contains a null byteRngError
if the generation of the temporary password failedWrongPassword
if the provided admin password is wrong
Example
use nitrokey::{Authenticate, Admin, DeviceWrapper}; fn perform_admin_task<'a>(device: &Admin<'a, DeviceWrapper<'a>>) {} fn perform_other_task(device: &DeviceWrapper) {} let mut manager = nitrokey::take()?; let device = manager.connect()?; let device = match device.authenticate_admin("123456") { Ok(admin) => { perform_admin_task(&admin); admin.device() }, Err((device, err)) => { eprintln!("Could not authenticate as admin: {}", err); device }, }; perform_other_task(&device);
Implementors
impl<'a> Authenticate<'a> for DeviceWrapper<'a>
[src]
fn authenticate_user(
self,
password: &str
) -> Result<User<'a, Self>, (Self, Error)>
[src]
self,
password: &str
) -> Result<User<'a, Self>, (Self, Error)>
fn authenticate_admin(
self,
password: &str
) -> Result<Admin<'a, Self>, (Self, Error)>
[src]
self,
password: &str
) -> Result<Admin<'a, Self>, (Self, Error)>
impl<'a> Authenticate<'a> for Pro<'a>
[src]
fn authenticate_user(
self,
password: &str
) -> Result<User<'a, Self>, (Self, Error)>
[src]
self,
password: &str
) -> Result<User<'a, Self>, (Self, Error)>
fn authenticate_admin(
self,
password: &str
) -> Result<Admin<'a, Self>, (Self, Error)>
[src]
self,
password: &str
) -> Result<Admin<'a, Self>, (Self, Error)>