Use slice::copy_from_slice in Transaction::change_pin
This commit is contained in:
+3
-28
@@ -16,8 +16,6 @@ use crate::{
|
|||||||
use log::{error, trace};
|
use log::{error, trace};
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
#[cfg(feature = "untested")]
|
#[cfg(feature = "untested")]
|
||||||
use std::ptr;
|
|
||||||
#[cfg(feature = "untested")]
|
|
||||||
use zeroize::Zeroizing;
|
use zeroize::Zeroizing;
|
||||||
|
|
||||||
/// Exclusive transaction with the YubiKey's PC/SC card.
|
/// Exclusive transaction with the YubiKey's PC/SC card.
|
||||||
@@ -187,7 +185,6 @@ impl<'tx> Transaction<'tx> {
|
|||||||
#[cfg(feature = "untested")]
|
#[cfg(feature = "untested")]
|
||||||
pub fn change_pin(&self, action: i32, current_pin: &[u8], new_pin: &[u8]) -> Result<(), Error> {
|
pub fn change_pin(&self, action: i32, current_pin: &[u8], new_pin: &[u8]) -> Result<(), Error> {
|
||||||
let mut templ = [0, Ins::ChangeReference.code(), 0, 0x80];
|
let mut templ = [0, Ins::ChangeReference.code(), 0, 0x80];
|
||||||
let mut indata = Zeroizing::new([0u8; 16]);
|
|
||||||
|
|
||||||
if current_pin.len() > CB_PIN_MAX || new_pin.len() > CB_PIN_MAX {
|
if current_pin.len() > CB_PIN_MAX || new_pin.len() > CB_PIN_MAX {
|
||||||
return Err(Error::SizeError);
|
return Err(Error::SizeError);
|
||||||
@@ -199,31 +196,9 @@ impl<'tx> Transaction<'tx> {
|
|||||||
templ[3] = 0x81;
|
templ[3] = 0x81;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
let mut indata = Zeroizing::new([0xff; CB_PIN_MAX * 2]);
|
||||||
ptr::copy(current_pin.as_ptr(), indata.as_mut_ptr(), current_pin.len());
|
indata[0..current_pin.len()].copy_from_slice(current_pin);
|
||||||
|
indata[CB_PIN_MAX..CB_PIN_MAX + new_pin.len()].copy_from_slice(new_pin);
|
||||||
if current_pin.len() < CB_PIN_MAX {
|
|
||||||
ptr::write_bytes(
|
|
||||||
indata.as_mut_ptr().add(current_pin.len()),
|
|
||||||
0xff,
|
|
||||||
CB_PIN_MAX - current_pin.len(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr::copy(
|
|
||||||
new_pin.as_ptr(),
|
|
||||||
indata.as_mut_ptr().offset(8),
|
|
||||||
new_pin.len(),
|
|
||||||
);
|
|
||||||
|
|
||||||
if new_pin.len() < CB_PIN_MAX {
|
|
||||||
ptr::write_bytes(
|
|
||||||
indata.as_mut_ptr().offset(8).add(new_pin.len()),
|
|
||||||
0xff,
|
|
||||||
CB_PIN_MAX - new_pin.len(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let status_words = self
|
let status_words = self
|
||||||
.transfer_data(&templ, indata.as_ref(), 0xFF)?
|
.transfer_data(&templ, indata.as_ref(), 0xFF)?
|
||||||
|
|||||||
Reference in New Issue
Block a user