use responses::Response;
use securechannel::{CommandMessage, CommandType};
use serde::ser::Serialize;
use serde::de::DeserializeOwned;
use serializers::serialize;
use {Algorithm, Capabilities, Domains, ObjectId, ObjectLabel, ObjectType};
use securechannel::Challenge;
use responses::*;
pub(crate) trait Command: Serialize + DeserializeOwned + Sized {
type ResponseType: Response;
const COMMAND_TYPE: CommandType = Self::ResponseType::COMMAND_TYPE;
}
impl<C: Command> From<C> for CommandMessage {
fn from(command: C) -> CommandMessage {
Self::new(C::COMMAND_TYPE, serialize(&command).unwrap()).unwrap()
}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BlinkCommand {
pub num_seconds: u8,
}
impl Command for BlinkCommand {
type ResponseType = BlinkResponse;
}
#[derive(Serialize, Deserialize, Debug)]
pub struct CreateSessionCommand {
pub auth_key_id: ObjectId,
pub host_challenge: Challenge,
}
impl Command for CreateSessionCommand {
type ResponseType = CreateSessionResponse;
}
#[derive(Serialize, Deserialize, Debug)]
pub struct DeleteObjectCommand {
pub object_id: ObjectId,
pub object_type: ObjectType,
}
impl Command for DeleteObjectCommand {
type ResponseType = DeleteObjectResponse;
}
#[derive(Serialize, Deserialize, Debug)]
pub struct EchoCommand {
pub message: Vec<u8>,
}
impl Command for EchoCommand {
type ResponseType = EchoResponse;
}
#[derive(Serialize, Deserialize, Debug)]
pub struct GenAsymmetricKeyCommand {
pub key_id: ObjectId,
pub label: ObjectLabel,
pub domains: Domains,
pub capabilities: Capabilities,
pub algorithm: Algorithm,
}
impl Command for GenAsymmetricKeyCommand {
type ResponseType = GenAsymmetricKeyResponse;
}
#[derive(Serialize, Deserialize, Debug)]
pub struct GetPubKeyCommand {
pub key_id: ObjectId,
}
impl Command for GetPubKeyCommand {
type ResponseType = GetPubKeyResponse;
}
#[derive(Serialize, Deserialize, Debug)]
pub struct GetObjectInfoCommand {
pub object_id: ObjectId,
pub object_type: ObjectType,
}
impl Command for GetObjectInfoCommand {
type ResponseType = GetObjectInfoResponse;
}
#[derive(Serialize, Deserialize, Debug)]
pub struct ListObjectsCommand {}
impl Command for ListObjectsCommand {
type ResponseType = ListObjectsResponse;
}
#[derive(Serialize, Deserialize, Debug)]
pub struct SignDataEdDSACommand {
pub key_id: ObjectId,
pub data: Vec<u8>,
}
impl Command for SignDataEdDSACommand {
type ResponseType = SignDataEdDSAResponse;
}