use std::fmt::{self, Debug};
use crate::command::{Command, CommandCode};
use crate::object::ObjectId;
use crate::response::Response;
pub const ED25519_SIGNATURE_SIZE: usize = 64;
#[derive(Serialize, Deserialize, Debug)]
pub(crate) struct SignDataEddsaCommand {
pub key_id: ObjectId,
pub data: Vec<u8>,
}
impl Command for SignDataEddsaCommand {
type ResponseType = Ed25519Signature;
}
pub struct Ed25519Signature(pub [u8; ED25519_SIGNATURE_SIZE]);
impl Response for Ed25519Signature {
const COMMAND_CODE: CommandCode = CommandCode::SignEddsa;
}
impl AsRef<[u8]> for Ed25519Signature {
fn as_ref(&self) -> &[u8] {
&self.0[..]
}
}
impl Debug for Ed25519Signature {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Ed25519Signature(")?;
for (i, byte) in self.0.iter().enumerate() {
write!(f, "{:02x}", byte)?;
write!(
f,
"{}",
if i == ED25519_SIGNATURE_SIZE - 1 {
")"
} else {
":"
}
)?;
}
Ok(())
}
}
impl_array_serializers!(Ed25519Signature, ED25519_SIGNATURE_SIZE);