frost/src/signature.rs

68 lines
1.6 KiB
Rust
Raw Normal View History

2019-12-03 13:39:26 -08:00
use std::{convert, fmt, marker::PhantomData};
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 {
2019-12-03 13:39:26 -08:00
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
2019-12-03 19:19:36 -08:00
impl<T: SigType> Signature<T> {
pub(crate) fn from_parts(r_bytes: [u8; 32], s_bytes: [u8; 32]) -> Self {
let mut bytes = [0; 64];
bytes[0..32].copy_from_slice(&r_bytes[..]);
bytes[32..64].copy_from_slice(&s_bytes[..]);
Self {
bytes,
_marker: PhantomData,
}
}
}
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 {
2019-12-03 13:39:26 -08:00
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> {}