From fa472112a82e2eca052cd8ed0a09c2849a665f67 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Mon, 28 May 2018 21:03:26 +0000 Subject: Move Admin, User and Authenticate to auth module --- src/misc.rs | 99 ------------------------------------------------------------- 1 file changed, 99 deletions(-) delete mode 100644 src/misc.rs (limited to 'src/misc.rs') diff --git a/src/misc.rs b/src/misc.rs deleted file mode 100644 index 16d5884..0000000 --- a/src/misc.rs +++ /dev/null @@ -1,99 +0,0 @@ -use device::{Admin, Device, User}; -use util::CommandError; - -/// 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. -pub trait Authenticate { - /// 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 byte - /// - [`RngError`][] if the generation of the temporary password failed - /// - [`WrongPassword`][] if the provided user password is wrong - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::{Authenticate, DeviceWrapper, User}; - /// # use nitrokey::CommandError; - /// - /// fn perform_user_task(device: &User) {} - /// fn perform_other_task(device: &DeviceWrapper) {} - /// - /// # fn try_main() -> Result<(), CommandError> { - /// let device = nitrokey::connect()?; - /// let device = match device.authenticate_user("123456") { - /// Ok(user) => { - /// perform_user_task(&user); - /// user.device() - /// }, - /// Err((device, err)) => { - /// println!("Could not authenticate as user: {:?}", err); - /// device - /// }, - /// }; - /// perform_other_task(&device); - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidString`]: enum.CommandError.html#variant.InvalidString - /// [`RngError`]: enum.CommandError.html#variant.RngError - /// [`WrongPassword`]: enum.CommandError.html#variant.WrongPassword - fn authenticate_user(self, password: &str) -> Result, (Self, CommandError)> - where - Self: Device + 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 byte - /// - [`RngError`][] if the generation of the temporary password failed - /// - [`WrongPassword`][] if the provided admin password is wrong - /// - /// # Example - /// - /// ```no_run - /// use nitrokey::{Authenticate, Admin, DeviceWrapper}; - /// # use nitrokey::CommandError; - /// - /// fn perform_admin_task(device: &Admin) {} - /// fn perform_other_task(device: &DeviceWrapper) {} - /// - /// # fn try_main() -> Result<(), CommandError> { - /// let device = nitrokey::connect()?; - /// let device = match device.authenticate_admin("123456") { - /// Ok(admin) => { - /// perform_admin_task(&admin); - /// admin.device() - /// }, - /// Err((device, err)) => { - /// println!("Could not authenticate as admin: {:?}", err); - /// device - /// }, - /// }; - /// perform_other_task(&device); - /// # Ok(()) - /// # } - /// ``` - /// - /// [`InvalidString`]: enum.CommandError.html#variant.InvalidString - /// [`RngError`]: enum.CommandError.html#variant.RngError - /// [`WrongPassword`]: enum.CommandError.html#variant.WrongPassword - fn authenticate_admin(self, password: &str) -> Result, (Self, CommandError)> - where - Self: Device + Sized; -} -- cgit v1.2.1