aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2018-05-22 08:55:45 +0000
committerRobin Krahl <robin.krahl@ireas.org>2018-05-22 10:57:28 +0200
commit2c31912bd2f8731c146da6640e28896c9de6286a (patch)
treea30eafed93f41667f342a72e25fb6f70c4b95254
parenta9657c48c8c92f6c82834a2abd90e27904e2cf6b (diff)
downloadnitrokey-rs-2c31912bd2f8731c146da6640e28896c9de6286a.tar.gz
nitrokey-rs-2c31912bd2f8731c146da6640e28896c9de6286a.tar.bz2
Improve OtpSlotData constructor / builder
Firstly, use Into<String> instead of String::from(&str). Secondly, add methods to set the two arguments not set in the constructor.
-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 {