diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2018-05-22 08:55:45 +0000 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2018-05-22 10:57:28 +0200 |
commit | 2c31912bd2f8731c146da6640e28896c9de6286a (patch) | |
tree | a30eafed93f41667f342a72e25fb6f70c4b95254 /src | |
parent | a9657c48c8c92f6c82834a2abd90e27904e2cf6b (diff) | |
download | nitrokey-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.
Diffstat (limited to 'src')
-rw-r--r-- | src/otp.rs | 28 |
1 files changed, 24 insertions, 4 deletions
@@ -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 { |