summaryrefslogtreecommitdiff
path: root/src/otp.rs
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-07-09 10:49:16 +0200
committerRobin Krahl <robin.krahl@ireas.org>2019-07-09 10:49:16 +0200
commit7ce751225f12c295c6e33dd46cfb5dcb88f8fbb3 (patch)
tree910e7fcae5b2b502900c67782b4db22d9c242f21 /src/otp.rs
parent445e920986db276d0c5c39709aa76dd290773e8f (diff)
parent62e8ee8f5d02511d6eb5dc179b087b04e88c1b94 (diff)
downloadnitrokey-rs-7ce751225f12c295c6e33dd46cfb5dcb88f8fbb3.tar.gz
nitrokey-rs-7ce751225f12c295c6e33dd46cfb5dcb88f8fbb3.tar.bz2
Merge branch 'connection-manager-mut' into next
Refactor the connection management to prevent multiple device connections at the same time. RFC: https://lists.sr.ht/~ireas/nitrokey-rs-dev/%3C20190126174327.tbuyk2s535kfiqm4%40localhost%3E
Diffstat (limited to 'src/otp.rs')
-rw-r--r--src/otp.rs27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/otp.rs b/src/otp.rs
index ee142c7..4667aff 100644
--- a/src/otp.rs
+++ b/src/otp.rs
@@ -35,7 +35,8 @@ pub trait ConfigureOtp {
/// # use nitrokey::Error;
///
/// # fn try_main() -> Result<(), Error> {
- /// let device = nitrokey::connect()?;
+ /// let mut manager = nitrokey::take()?;
+ /// let device = manager.connect()?;
/// let slot_data = OtpSlotData::new(1, "test", "01234567890123456689", OtpMode::SixDigits);
/// match device.authenticate_admin("12345678") {
/// Ok(mut admin) => {
@@ -71,7 +72,8 @@ pub trait ConfigureOtp {
/// # use nitrokey::Error;
///
/// # fn try_main() -> Result<(), Error> {
- /// let device = nitrokey::connect()?;
+ /// let mut manager = nitrokey::take()?;
+ /// let device = manager.connect()?;
/// let slot_data = OtpSlotData::new(1, "test", "01234567890123456689", OtpMode::EightDigits);
/// match device.authenticate_admin("12345678") {
/// Ok(mut admin) => {
@@ -104,7 +106,8 @@ pub trait ConfigureOtp {
/// # use nitrokey::Error;
///
/// # fn try_main() -> Result<(), Error> {
- /// let device = nitrokey::connect()?;
+ /// let mut manager = nitrokey::take()?;
+ /// let device = manager.connect()?;
/// match device.authenticate_admin("12345678") {
/// Ok(mut admin) => {
/// match admin.erase_hotp_slot(1) {
@@ -134,7 +137,8 @@ pub trait ConfigureOtp {
/// # use nitrokey::Error;
///
/// # fn try_main() -> Result<(), Error> {
- /// let device = nitrokey::connect()?;
+ /// let mut manager = nitrokey::take()?;
+ /// let device = manager.connect()?;
/// match device.authenticate_admin("12345678") {
/// Ok(mut admin) => {
/// match admin.erase_totp_slot(1) {
@@ -171,7 +175,8 @@ pub trait GenerateOtp {
/// # use nitrokey::Error;
///
/// # fn try_main() -> Result<(), Error> {
- /// let mut device = nitrokey::connect()?;
+ /// let mut manager = nitrokey::take()?;
+ /// let mut device = manager.connect()?;
/// let time = time::SystemTime::now().duration_since(time::UNIX_EPOCH);
/// match time {
/// Ok(time) => device.set_time(time.as_secs(), false)?,
@@ -209,7 +214,8 @@ pub trait GenerateOtp {
/// use nitrokey::{CommandError, Error, GenerateOtp};
///
/// # fn try_main() -> Result<(), Error> {
- /// let device = nitrokey::connect()?;
+ /// let mut manager = nitrokey::take()?;
+ /// let device = manager.connect()?;
/// match device.get_hotp_slot_name(1) {
/// Ok(name) => println!("HOTP slot 1: {}", name),
/// Err(Error::CommandError(CommandError::SlotNotProgrammed)) => eprintln!("HOTP slot 1 not programmed"),
@@ -238,7 +244,8 @@ pub trait GenerateOtp {
/// use nitrokey::{CommandError, Error, GenerateOtp};
///
/// # fn try_main() -> Result<(), Error> {
- /// let device = nitrokey::connect()?;
+ /// let mut manager = nitrokey::take()?;
+ /// let device = manager.connect()?;
/// match device.get_totp_slot_name(1) {
/// Ok(name) => println!("TOTP slot 1: {}", name),
/// Err(Error::CommandError(CommandError::SlotNotProgrammed)) => eprintln!("TOTP slot 1 not programmed"),
@@ -270,7 +277,8 @@ pub trait GenerateOtp {
/// # use nitrokey::Error;
///
/// # fn try_main() -> Result<(), Error> {
- /// let mut device = nitrokey::connect()?;
+ /// let mut manager = nitrokey::take()?;
+ /// let mut device = manager.connect()?;
/// let code = device.get_hotp_code(1)?;
/// println!("Generated HOTP code on slot 1: {}", code);
/// # Ok(())
@@ -305,7 +313,8 @@ pub trait GenerateOtp {
/// # use nitrokey::Error;
///
/// # fn try_main() -> Result<(), Error> {
- /// let mut device = nitrokey::connect()?;
+ /// let mut manager = nitrokey::take()?;
+ /// let mut device = manager.connect()?;
/// let time = time::SystemTime::now().duration_since(time::UNIX_EPOCH);
/// match time {
/// Ok(time) => {