frost/src/signature.rs

54 lines
1.2 KiB
Rust
Raw Normal View History

use std::{marker::PhantomData, convert, fmt};
use crate::SigType;
2019-12-02 22:10:56 -08:00
2019-12-02 21:58:19 -08:00
/// A RedJubJub signature.
pub struct Signature<T: SigType> {
bytes: [u8; 64],
_marker: PhantomData<T>,
}
2019-12-02 21:58:19 -08:00
impl<T: SigType> From<[u8; 64]> for Signature<T> {
fn from(bytes: [u8; 64]) -> Signature<T> {
Signature {
bytes, _marker: PhantomData,
}
2019-12-02 21:58:19 -08:00
}
}
impl<T: SigType> From<Signature<T>> for [u8; 64] {
fn from(s: Signature<T>) -> [u8; 64] {
s.bytes
2019-12-02 21:58:19 -08:00
}
}
2019-12-02 22:10:56 -08:00
// These impls all only exist because of array length restrictions.
// XXX print the type variable
impl<T: SigType> fmt::Debug for Signature<T> {
2019-12-02 22:10:56 -08:00
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
//f.debug_tuple("Signature").field(&self.0[..]).finish()
f.debug_tuple("Signature").finish()
2019-12-02 22:10:56 -08:00
}
}
impl<T: SigType> Copy for Signature<T> {}
2019-12-02 22:10:56 -08:00
impl<T: SigType> Clone for Signature<T> {
2019-12-02 22:10:56 -08:00
fn clone(&self) -> Self {
let mut bytes = [0; 64];
bytes[..].copy_from_slice(&self.bytes[..]);
Signature {
bytes, _marker: PhantomData,
}
2019-12-02 22:10:56 -08:00
}
}
impl<T: SigType> PartialEq for Signature<T> {
2019-12-02 22:10:56 -08:00
fn eq(&self, other: &Self) -> bool {
self.bytes[..] == other.bytes[..]
2019-12-02 22:10:56 -08:00
}
}
impl<T: SigType> Eq for Signature<T> {}