use crate::{
Error, Instruction, StatusCode, Uid,
client::{Authenticated, Card, Session},
io,
};
impl<'card, IoBackendT> Card<'card, IoBackendT, Authenticated>
where
IoBackendT: io::Backend,
{
pub async fn get_uid(&mut self, out: &mut [u8]) -> Result<Uid, Error<IoBackendT::Error>> {
let (status_code, response) = match &mut self.authentication.session {
Session::Des { keying, .. } => {
io::plain_out_encrypted_in(
&self.card,
keying,
out,
&[Instruction::GetUid as u8],
&[],
)
.await?
}
Session::Aes { keying, .. } => {
io::plain_out_encrypted_in(
&self.card,
keying,
out,
&[Instruction::GetUid as u8],
&[],
)
.await?
}
};
let response = &response[..7 + 4];
let response = io::check_crc32(response, &[&[status_code.into()]])?;
if status_code != StatusCode::Ack {
return Err(Error::BadStatusCode(status_code));
}
let uid: &Uid = response.try_into().map_err(|_| Error::BadSize)?;
Ok(*uid)
}
}