use crate::{
Error, Key, KeyId,
client::{AuthenticateExt, Authenticated, AuthenticationState, Card, KeyingState, Session},
io,
};
impl<'card, IoBackendT, AuthenticationStateT> Card<'card, IoBackendT, AuthenticationStateT>
where
AuthenticationStateT: AuthenticationState,
IoBackendT: io::Backend,
IoBackendT: AuthenticateExt<8, des::Des>,
IoBackendT: AuthenticateExt<16, aes::Aes128>,
{
pub async fn authenticate(
self,
key_id: KeyId,
key: Key,
) -> Result<Card<'card, IoBackendT, Authenticated>, Error<IoBackendT::Error>> {
let session: Session = match key {
Key::Aes(key) => {
let session_key =
AuthenticateExt::<16, aes::Aes128>::authenticate(&self.card, key_id, key)
.await?;
Session::Aes {
key_id,
keying: KeyingState::<16, aes::Aes128>::new(session_key),
}
}
Key::Des(key) => {
let session_key =
AuthenticateExt::<8, des::Des>::authenticate(&self.card, key_id, key).await?;
Session::Des {
key_id,
keying: KeyingState::<8, des::Des>::new(session_key),
}
}
};
let Self {
card,
buf,
authentication: _,
} = self;
Ok(Card {
card,
buf,
authentication: Authenticated { session },
})
}
}