use signature::{SignatureEncoding, Signer, Verifier};
#[derive(Clone)]
pub struct NoSignature;
impl SignatureEncoding for NoSignature {
type Repr = [u8; 0];
}
impl<'a> TryFrom<&'a [u8]> for NoSignature {
type Error = ();
fn try_from(value: &'a [u8]) -> Result<Self, Self::Error> {
if !value.is_empty() {
return Err(());
}
Ok(NoSignature)
}
}
impl TryInto<[u8; 0]> for NoSignature {
type Error = ();
fn try_into(self) -> Result<[u8; 0], Self::Error> {
Ok([0; 0])
}
}
#[derive(Clone)]
pub struct NoSigningKey;
impl Signer<NoSignature> for NoSigningKey {
fn try_sign(&self, _msg: &[u8]) -> Result<NoSignature, signature::Error> {
Ok(NoSignature)
}
}
#[derive(Clone)]
pub struct NoVerifyingKey(Vec<u8>);
impl NoVerifyingKey {
pub fn new(id: usize) -> Self {
NoVerifyingKey((id as u64).to_be_bytes().into())
}
}
impl<T: Into<Vec<u8>>> From<T> for NoVerifyingKey {
fn from(value: T) -> Self {
NoVerifyingKey(value.into())
}
}
impl AsRef<[u8]> for NoVerifyingKey {
fn as_ref(&self) -> &[u8] {
&self.0
}
}
impl Verifier<NoSignature> for NoVerifyingKey {
fn verify(
&self,
_: &[u8],
_: &NoSignature,
) -> Result<(), signature::Error> {
Ok(())
}
}