summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/otp.rs28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/otp.rs b/src/otp.rs
index c0a470f..c951d5f 100644
--- a/src/otp.rs
+++ b/src/otp.rs
@@ -295,7 +295,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 [OATH Token Identifier Specification][tokspec], section
+ /// Set the token ID, see [OATH Token Identifier Specification][tokspec], section
/// “Class A”.
///
/// [tokspec]: https://openauthentication.org/token-specs/
@@ -315,16 +315,36 @@ pub struct RawOtpSlotData {
impl OtpSlotData {
/// Constructs a new instance of this struct.
- pub fn new(number: u8, name: &str, secret: &str, mode: OtpMode) -> OtpSlotData {
+ pub fn new<S: Into<String>, T: Into<String>>(
+ number: u8,
+ name: S,
+ secret: T,
+ mode: OtpMode,
+ ) -> OtpSlotData {
OtpSlotData {
number,
- name: String::from(name),
- secret: String::from(secret),
+ name: name.into(),
+ secret: secret.into(),
mode,
use_enter: false,
token_id: None,
}
}
+
+ /// Enables pressing the enter key after sending an OTP code using double-pressed numlock,
+ /// capslock or scrollock.
+ pub fn use_enter(mut self) -> OtpSlotData {
+ self.use_enter = true;
+ self
+ }
+
+ /// Sets the token ID, see [OATH Token Identifier Specification][tokspec], section “Class A”.
+ ///
+ /// [tokspec]: https://openauthentication.org/token-specs/
+ pub fn token_id<S: Into<String>>(mut self, id: S) -> OtpSlotData {
+ self.token_id = Some(id.into());
+ self
+ }
}
impl RawOtpSlotData {