aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/config.rs17
-rw-r--r--src/device.rs53
-rw-r--r--src/lib.rs25
-rw-r--r--src/misc.rs20
-rw-r--r--src/otp.rs28
-rw-r--r--src/util.rs6
6 files changed, 68 insertions, 81 deletions
diff --git a/src/config.rs b/src/config.rs
index b37c9d3..33bf256 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -3,18 +3,17 @@ use util::CommandError;
/// The configuration for a Nitrokey.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Config {
- /// If set, the stick will generate a code from the HOTP slot with the
- /// given number if numlock is pressed. The slot number must be 0, 1 or 2.
+ /// If set, the stick will generate a code from the HOTP slot with the given number if numlock
+ /// is pressed. The slot number must be 0, 1 or 2.
pub numlock: Option<u8>,
- /// If set, the stick will generate a code from the HOTP slot with the
- /// given number if capslock is pressed. The slot number must be 0, 1 or 2.
+ /// If set, the stick will generate a code from the HOTP slot with the given number if capslock
+ /// is pressed. The slot number must be 0, 1 or 2.
pub capslock: Option<u8>,
- /// If set, the stick will generate a code from the HOTP slot with the
- /// given number if scrollock is pressed. The slot number must be 0, 1 or 2.
+ /// If set, the stick will generate a code from the HOTP slot with the given number if
+ /// scrollock is pressed. The slot number must be 0, 1 or 2.
pub scrollock: Option<u8>,
- /// If set, OTP generation using [`get_hotp_code`][] or [`get_totp_code`][]
- /// requires user authentication. Otherwise, OTPs can be generated without
- /// authentication.
+ /// If set, OTP generation using [`get_hotp_code`][] or [`get_totp_code`][] requires user
+ /// authentication. Otherwise, OTPs can be generated without authentication.
///
/// [`get_hotp_code`]: trait.ProvideOtp.html#method.get_hotp_code
/// [`get_totp_code`]: trait.ProvideOtp.html#method.get_totp_code
diff --git a/src/device.rs b/src/device.rs
index d24bf51..277218e 100644
--- a/src/device.rs
+++ b/src/device.rs
@@ -140,9 +140,8 @@ pub struct Admin<T: Device> {
/// This trait provides the commands that can be executed without authentication and that are
/// present on all supported Nitrokey devices.
pub trait Device: GenerateOtp {
- /// Sets the time on the Nitrokey. This command may set the time to
- /// arbitrary values. `time` is the number of seconds since January 1st,
- /// 1970 (Unix timestamp).
+ /// Sets the time on the Nitrokey. This command may set the time to arbitrary values. `time`
+ /// is the number of seconds since January 1st, 1970 (Unix timestamp).
///
/// The time is used for TOTP generation (see [`get_totp_code`][]).
///
@@ -177,8 +176,8 @@ pub trait Device: GenerateOtp {
unsafe { CommandStatus::from(nitrokey_sys::NK_totp_set_time(time)) }
}
- /// Returns the serial number of the Nitrokey device. The serial number
- /// is the string representation of a hex number.
+ /// Returns the serial number of the Nitrokey device. The serial number is the string
+ /// representation of a hex number.
///
/// # Example
///
@@ -199,8 +198,8 @@ pub trait Device: GenerateOtp {
unsafe { result_from_string(nitrokey_sys::NK_device_serial_number()) }
}
- /// Returns the number of remaining authentication attempts for the user. The
- /// total number of available attempts is three.
+ /// Returns the number of remaining authentication attempts for the user. The total number of
+ /// available attempts is three.
///
/// # Example
///
@@ -219,8 +218,8 @@ pub trait Device: GenerateOtp {
unsafe { nitrokey_sys::NK_get_user_retry_count() }
}
- /// Returns the number of remaining authentication attempts for the admin. The
- /// total number of available attempts is three.
+ /// Returns the number of remaining authentication attempts for the admin. The total number of
+ /// available attempts is three.
///
/// # Example
///
@@ -261,8 +260,7 @@ pub trait Device: GenerateOtp {
unsafe { nitrokey_sys::NK_get_major_firmware_version() }
}
- /// Returns the minor part of the firmware version (for example 8 for
- /// version 0.8).
+ /// Returns the minor part of the firmware version (for example 8 for version 0.8).
///
/// # Example
///
@@ -401,8 +399,8 @@ trait AuthenticatedDevice<T> {
fn new(device: T, temp_password: Vec<u8>) -> Self;
}
-/// Connects to a Nitrokey device. This method can be used to connect to any
-/// connected device, both a Nitrokey Pro and a Nitrokey Storage.
+/// Connects to a Nitrokey device. This method can be used to connect to any connected device,
+/// both a Nitrokey Pro and a Nitrokey Storage.
///
/// # Example
///
@@ -579,18 +577,17 @@ impl<T: Device + 'static> AsRef<Device> for User<T> {
}
impl<T: Device> User<T> {
- /// Forgets the user authentication and returns an unauthenticated
- /// device. This method consumes the authenticated device. It does not
- /// perform any actual commands on the Nitrokey.
+ /// Forgets the user authentication and returns an unauthenticated device. This method
+ /// consumes the authenticated device. It does not perform any actual commands on the
+ /// Nitrokey.
pub fn device(self) -> T {
self.device
}
}
impl<T: Device> GenerateOtp for User<T> {
- /// Generates an HOTP code on the given slot. This operation may not
- /// require user authorization, depending on the device configuration (see
- /// [`get_config`][]).
+ /// Generates an HOTP code on the given slot. This operation may not require user
+ /// authorization, depending on the device configuration (see [`get_config`][]).
///
/// # Errors
///
@@ -626,12 +623,11 @@ impl<T: Device> GenerateOtp for User<T> {
}
}
- /// Generates a TOTP code on the given slot. This operation may not
- /// require user authorization, depending on the device configuration (see
- /// [`get_config`][]).
+ /// Generates a TOTP code on the given slot. This operation may not require user
+ /// authorization, depending on the device configuration (see [`get_config`][]).
///
- /// To make sure that the Nitrokey’s time is in sync, consider calling
- /// [`set_time`][] before calling this method.
+ /// To make sure that the Nitrokey’s time is in sync, consider calling [`set_time`][] before
+ /// calling this method.
///
/// # Errors
///
@@ -697,9 +693,9 @@ impl<T: Device + 'static> AsRef<Device> for Admin<T> {
}
impl<T: Device> Admin<T> {
- /// Forgets the user authentication and returns an unauthenticated
- /// device. This method consumes the authenticated device. It does not
- /// perform any actual commands on the Nitrokey.
+ /// Forgets the user authentication and returns an unauthenticated device. This method
+ /// consumes the authenticated device. It does not perform any actual commands on the
+ /// Nitrokey.
pub fn device(self) -> T {
self.device
}
@@ -708,8 +704,7 @@ impl<T: Device> Admin<T> {
///
/// # Errors
///
- /// - [`InvalidSlot`][] if the provided numlock, capslock or scrolllock
- /// slot is larger than two
+ /// - [`InvalidSlot`][] if the provided numlock, capslock or scrolllock slot is larger than two
///
/// # Example
///
diff --git a/src/lib.rs b/src/lib.rs
index 03ef1ea..41603a0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -14,12 +14,10 @@
//! device that can perform operations that require authentication. You can use [`device`][] to go
//! back to the unauthenticated device.
//!
-//! This makes sure that you can only execute a command if you have the
-//! required access rights. Otherwise, your code will not compile. The only
-//! exception are the methods to generate one-time passwords –
-//! [`get_hotp_code`][] and [`get_totp_code`][]. Depending on the stick
-//! configuration, these operations are available without authentication or
-//! with user authentication.
+//! This makes sure that you can only execute a command if you have the required access rights.
+//! Otherwise, your code will not compile. The only exception are the methods to generate one-time
+//! passwords – [`get_hotp_code`][] and [`get_totp_code`][]. Depending on the stick configuration,
+//! these operations are available without authentication or with user authentication.
//!
//! # Examples
//!
@@ -103,12 +101,12 @@ pub use misc::Authenticate;
pub use otp::{ConfigureOtp, GenerateOtp, OtpMode, OtpSlotData};
pub use util::{CommandError, CommandStatus, LogLevel};
-/// Enables or disables debug output. Calling this method with `true` is
-/// equivalent to setting the log level to `Debug`; calling it with `false` is
-/// equivalent to the log level `Error` (see [`set_log_level`][]).
+/// Enables or disables debug output. Calling this method with `true` is equivalent to setting the
+/// log level to `Debug`; calling it with `false` is equivalent to the log level `Error` (see
+/// [`set_log_level`][]).
///
-/// If debug output is enabled, detailed information about the communication
-/// with the Nitrokey device is printed to the standard output.
+/// If debug output is enabled, detailed information about the communication with the Nitrokey
+/// device is printed to the standard output.
///
/// [`set_log_level`]: fn.set_log_level.html
pub fn set_debug(state: bool) {
@@ -117,9 +115,8 @@ pub fn set_debug(state: bool) {
}
}
-/// Sets the log level for libnitrokey. All log messages are written to the
-/// standard error stream. Setting the log level enables all log messages on
-/// the same or on a higher log level.
+/// Sets the log level for libnitrokey. All log messages are written to the standard error stream.
+/// Setting the log level enables all log messages on the same or on a higher log level.
pub fn set_log_level(level: LogLevel) {
unsafe {
nitrokey_sys::NK_set_debug_level(level.into());
diff --git a/src/misc.rs b/src/misc.rs
index 42f8639..16d5884 100644
--- a/src/misc.rs
+++ b/src/misc.rs
@@ -5,12 +5,12 @@ use util::CommandError;
/// 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.
+ /// 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.
+ /// This method generates a random temporary password that is used for all operations that
+ /// require user access.
///
/// # Errors
///
@@ -51,12 +51,12 @@ pub trait Authenticate {
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.
+ /// 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.
+ /// This method generates a random temporary password that is used for all operations that
+ /// require admin access.
///
/// # Errors
///
diff --git a/src/otp.rs b/src/otp.rs
index 7145b6c..0d04e27 100644
--- a/src/otp.rs
+++ b/src/otp.rs
@@ -13,8 +13,8 @@ pub enum OtpMode {
/// Provides methods to configure and erase OTP slots on a Nitrokey device.
pub trait ConfigureOtp {
- /// Configure an HOTP slot with the given data and set the HOTP counter to
- /// the given value (default 0).
+ /// Configure an HOTP slot with the given data and set the HOTP counter to the given value
+ /// (default 0).
///
/// # Errors
///
@@ -49,8 +49,8 @@ pub trait ConfigureOtp {
/// [`NoName`]: enum.CommandError.html#variant.NoName
fn write_hotp_slot(&self, data: OtpSlotData, counter: u64) -> CommandStatus;
- /// Configure a TOTP slot with the given data and set the TOTP time window
- /// to the given value (default 30).
+ /// Configure a TOTP slot with the given data and set the TOTP time window to the given value
+ /// (default 30).
///
/// # Errors
///
@@ -207,9 +207,8 @@ pub trait GenerateOtp {
unsafe { result_from_string(nitrokey_sys::NK_get_totp_slot_name(slot)) }
}
- /// Generates an HOTP code on the given slot. This operation may require
- /// user authorization, depending on the device configuration (see
- /// [`get_config`][]).
+ /// Generates an HOTP code on the given slot. This operation may require user authorization,
+ /// depending on the device configuration (see [`get_config`][]).
///
/// # Errors
///
@@ -241,12 +240,11 @@ pub trait GenerateOtp {
}
}
- /// Generates a TOTP code on the given slot. This operation may require
- /// user authorization, depending on the device configuration (see
- /// [`get_config`][]).
+ /// Generates a TOTP code on the given slot. This operation may require user authorization,
+ /// depending on the device configuration (see [`get_config`][]).
///
- /// To make sure that the Nitrokey’s time is in sync, consider calling
- /// [`set_time`][] before calling this method.
+ /// To make sure that the Nitrokey’s time is in sync, consider calling [`set_time`][] before
+ /// calling this method.
///
/// # Errors
///
@@ -291,8 +289,7 @@ pub trait GenerateOtp {
/// The configuration for an OTP slot.
#[derive(Debug)]
pub struct OtpSlotData {
- /// The number of the slot – must be less than three for HOTP and less than
- /// 15 for TOTP.
+ /// The number of the slot – must be less than three for HOTP and less than 15 for TOTP.
pub number: u8,
/// The name of the slot – must not be empty.
pub name: String,
@@ -303,8 +300,7 @@ pub struct OtpSlotData {
/// If true, press the enter key after sending an OTP code using double-pressed
/// numlock, capslock or scrolllock.
pub use_enter: bool,
- /// Set the token ID, see [OATH Token Identifier Specification][tokspec], section
- /// “Class A”.
+ /// Set the token ID, see [OATH Token Identifier Specification][tokspec], section “Class A”.
///
/// [tokspec]: https://openauthentication.org/token-specs/
pub token_id: Option<String>,
diff --git a/src/util.rs b/src/util.rs
index d380de4..22cccb3 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -48,9 +48,9 @@ pub enum CommandStatus {
Error(CommandError),
}
-/// Log level for libnitrokey. Setting the log level to a lower level enables
-/// all output from higher levels too. Currently, only the log levels `Warning`,
-/// `DebugL1`, `Debug` and `DebugL2` are actually used.
+/// Log level for libnitrokey. Setting the log level to a lower level enables all output from
+/// higher levels too. Currently, only the log levels `Warning`, `DebugL1`, `Debug` and `DebugL2`
+/// are actually used.
#[derive(Debug, PartialEq)]
pub enum LogLevel {
/// Error messages. Currently not used.