aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2020-01-28 19:47:39 +0100
committerRobin Krahl <robin.krahl@ireas.org>2020-01-28 21:05:13 +0100
commit777cbd0fee8187325b0272d3264b535828d4b4ea (patch)
tree99a1d543239da1a9a9d4c88dcf55bcfbdb52c031 /src
parent669fbb40d894460e9603dcf6e953373e53a19347 (diff)
downloadnitrokey-rs-777cbd0fee8187325b0272d3264b535828d4b4ea.tar.gz
nitrokey-rs-777cbd0fee8187325b0272d3264b535828d4b4ea.tar.bz2
Remove AuthenticatedDevice::temp_password_ptr
We introduced the AuthenticatedDevice::temp_password_ptr function to reduce the number of casts needed in our code base. Since we switched from Vec<u8> to CString, we no longer have to cast the return value of as_ptr. Therefore we can remove the temp_password_ptr function to reduce code complexity.
Diffstat (limited to 'src')
-rw-r--r--src/auth.rs24
1 files changed, 7 insertions, 17 deletions
diff --git a/src/auth.rs b/src/auth.rs
index 571e198..6748ca1 100644
--- a/src/auth.rs
+++ b/src/auth.rs
@@ -119,8 +119,6 @@ pub trait Authenticate<'a> {
trait AuthenticatedDevice<T> {
fn new(device: T, temp_password: CString) -> Self;
-
- fn temp_password_ptr(&self) -> *const c_char;
}
/// A Nitrokey device with user authentication.
@@ -235,13 +233,13 @@ impl<'a, T: Device<'a>> ops::DerefMut for User<'a, T> {
impl<'a, T: Device<'a>> GenerateOtp for User<'a, T> {
fn get_hotp_code(&mut self, slot: u8) -> Result<String, Error> {
result_from_string(unsafe {
- nitrokey_sys::NK_get_hotp_code_PIN(slot, self.temp_password_ptr())
+ nitrokey_sys::NK_get_hotp_code_PIN(slot, self.temp_password.as_ptr())
})
}
fn get_totp_code(&self, slot: u8) -> Result<String, Error> {
result_from_string(unsafe {
- nitrokey_sys::NK_get_totp_code_PIN(slot, 0, 0, 0, self.temp_password_ptr())
+ nitrokey_sys::NK_get_totp_code_PIN(slot, 0, 0, 0, self.temp_password.as_ptr())
})
}
}
@@ -254,10 +252,6 @@ impl<'a, T: Device<'a>> AuthenticatedDevice<T> for User<'a, T> {
marker: marker::PhantomData,
}
}
-
- fn temp_password_ptr(&self) -> *const c_char {
- self.temp_password.as_ptr()
- }
}
impl<'a, T: Device<'a>> ops::Deref for Admin<'a, T> {
@@ -319,7 +313,7 @@ impl<'a, T: Device<'a>> Admin<'a, T> {
raw_config.scrollock,
raw_config.user_password,
false,
- self.temp_password_ptr(),
+ self.temp_password.as_ptr(),
)
})
}
@@ -338,7 +332,7 @@ impl<'a, T: Device<'a>> ConfigureOtp for Admin<'a, T> {
raw_data.use_enter,
raw_data.use_token_id,
raw_data.token_id.as_ptr(),
- self.temp_password_ptr(),
+ self.temp_password.as_ptr(),
)
})
}
@@ -355,20 +349,20 @@ impl<'a, T: Device<'a>> ConfigureOtp for Admin<'a, T> {
raw_data.use_enter,
raw_data.use_token_id,
raw_data.token_id.as_ptr(),
- self.temp_password_ptr(),
+ self.temp_password.as_ptr(),
)
})
}
fn erase_hotp_slot(&mut self, slot: u8) -> Result<(), Error> {
get_command_result(unsafe {
- nitrokey_sys::NK_erase_hotp_slot(slot, self.temp_password_ptr())
+ nitrokey_sys::NK_erase_hotp_slot(slot, self.temp_password.as_ptr())
})
}
fn erase_totp_slot(&mut self, slot: u8) -> Result<(), Error> {
get_command_result(unsafe {
- nitrokey_sys::NK_erase_totp_slot(slot, self.temp_password_ptr())
+ nitrokey_sys::NK_erase_totp_slot(slot, self.temp_password.as_ptr())
})
}
}
@@ -381,10 +375,6 @@ impl<'a, T: Device<'a>> AuthenticatedDevice<T> for Admin<'a, T> {
marker: marker::PhantomData,
}
}
-
- fn temp_password_ptr(&self) -> *const c_char {
- self.temp_password.as_ptr()
- }
}
impl<'a> Authenticate<'a> for DeviceWrapper<'a> {