pub use failure::Error;
pub(crate) use securechannel::CommandType;
#[cfg(feature = "mockhsm")]
use securechannel::ResponseMessage;
use serde::ser::Serialize;
use serde::de::DeserializeOwned;
use {Algorithm, Capabilities, Domains, ObjectId, ObjectLabel, ObjectOrigin, ObjectType, SequenceId};
use securechannel::{Challenge, Cryptogram};
#[cfg(feature = "mockhsm")]
use serializers::serialize;
pub(crate) trait Response: Serialize + DeserializeOwned + Sized {
const COMMAND_TYPE: CommandType;
#[cfg(feature = "mockhsm")]
fn serialize(&self) -> ResponseMessage {
ResponseMessage::success(Self::COMMAND_TYPE, serialize(self).unwrap())
}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BlinkResponse {}
impl Response for BlinkResponse {
const COMMAND_TYPE: CommandType = CommandType::Blink;
}
#[derive(Serialize, Deserialize, Debug)]
pub struct CreateSessionResponse {
pub card_challenge: Challenge,
pub card_cryptogram: Cryptogram,
}
impl Response for CreateSessionResponse {
const COMMAND_TYPE: CommandType = CommandType::CreateSession;
}
#[derive(Serialize, Deserialize, Debug)]
pub struct DeleteObjectResponse {}
impl Response for DeleteObjectResponse {
const COMMAND_TYPE: CommandType = CommandType::DeleteObject;
}
#[derive(Serialize, Deserialize, Debug)]
pub struct EchoResponse {
pub message: Vec<u8>,
}
impl Response for EchoResponse {
const COMMAND_TYPE: CommandType = CommandType::Echo;
}
#[derive(Serialize, Deserialize, Debug)]
pub struct GenAsymmetricKeyResponse {
pub key_id: ObjectId,
}
impl Response for GenAsymmetricKeyResponse {
const COMMAND_TYPE: CommandType = CommandType::GenAsymmetricKey;
}
#[derive(Serialize, Deserialize, Debug)]
pub struct GetObjectInfoResponse {
pub capabilities: Capabilities,
pub id: u16,
pub length: u16,
pub domains: Domains,
pub object_type: ObjectType,
pub algorithm: Algorithm,
pub sequence: SequenceId,
pub origin: ObjectOrigin,
pub label: ObjectLabel,
pub delegated_capabilities: Capabilities,
}
impl Response for GetObjectInfoResponse {
const COMMAND_TYPE: CommandType = CommandType::GetObjectInfo;
}
#[derive(Serialize, Deserialize, Debug)]
pub struct GetPubKeyResponse {
pub algorithm: Algorithm,
pub data: Vec<u8>,
}
impl Response for GetPubKeyResponse {
const COMMAND_TYPE: CommandType = CommandType::GetPubKey;
}
#[derive(Serialize, Deserialize, Debug)]
pub struct ListObjectsResponse {
pub objects: Vec<ListObjectsEntry>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct ListObjectsEntry {
pub id: ObjectId,
pub object_type: ObjectType,
pub sequence: SequenceId,
}
impl Response for ListObjectsResponse {
const COMMAND_TYPE: CommandType = CommandType::ListObjects;
}
#[derive(Serialize, Deserialize, Debug)]
pub struct SignDataEdDSAResponse {
pub signature: Vec<u8>,
}
impl Response for SignDataEdDSAResponse {
const COMMAND_TYPE: CommandType = CommandType::SignDataEdDSA;
}