use std::fmt::{self, Debug};
use crate::{
command, response,
session::{
securechannel::{Challenge, Cryptogram, SecureChannel},
Id,
},
};
pub(crate) struct HsmSession {
pub id: Id,
pub card_challenge: Challenge,
pub channel: SecureChannel,
}
impl HsmSession {
pub fn new(id: Id, card_challenge: Challenge, channel: SecureChannel) -> Self {
Self {
id,
card_challenge,
channel,
}
}
pub fn card_challenge(&self) -> &Challenge {
&self.card_challenge
}
pub fn card_cryptogram(&self) -> Cryptogram {
self.channel.card_cryptogram()
}
pub fn decrypt_command(&mut self, command: command::Message) -> command::Message {
self.channel.decrypt_command(command).unwrap()
}
pub fn encrypt_response(&mut self, response: response::Message) -> response::Message {
self.channel.encrypt_response(response).unwrap()
}
}
impl Debug for HsmSession {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "mockhsm::Session {{ id: {} }}", self.id.to_u8())
}
}