use crate::context::Function;
use crate::error::{Result, Rv};
use crate::session::Session;
use crate::types::AuthPin;
use secrecy::ExposeSecret;
use std::convert::TryInto;
impl Session {
pub fn init_pin(&self, pin: &AuthPin) -> Result<()> {
unsafe {
Rv::from(get_pkcs11!(self.client(), C_InitPIN)(
self.handle(),
pin.expose_secret().as_ptr() as *mut u8,
pin.expose_secret().len().try_into()?,
))
.into_result(Function::InitPIN)
}
}
pub fn set_pin(&self, old_pin: &AuthPin, new_pin: &AuthPin) -> Result<()> {
unsafe {
Rv::from(get_pkcs11!(self.client(), C_SetPIN)(
self.handle(),
old_pin.expose_secret().as_ptr() as *mut u8,
old_pin.expose_secret().len().try_into()?,
new_pin.expose_secret().as_ptr() as *mut u8,
new_pin.expose_secret().len().try_into()?,
))
.into_result(Function::SetPIN)
}
}
}