diff --git a/src/secret_key.rs b/src/secret_key.rs index 4370328..031c803 100644 --- a/src/secret_key.rs +++ b/src/secret_key.rs @@ -79,6 +79,10 @@ impl SecretKey { let s_bytes = (&nonce + &(&c * &self.sk)).to_bytes(); - Signature::from_parts(r_bytes, s_bytes) + Signature{ + r_bytes, + s_bytes, + _marker: PhantomData, + } } } diff --git a/src/signature.rs b/src/signature.rs index 8514e80..6351676 100644 --- a/src/signature.rs +++ b/src/signature.rs @@ -3,65 +3,33 @@ use std::{convert, fmt, marker::PhantomData}; use crate::SigType; /// A RedJubJub signature. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct Signature { - bytes: [u8; 64], - _marker: PhantomData, + pub(crate) r_bytes: [u8; 32], + pub(crate) s_bytes: [u8; 32], + pub(crate) _marker: PhantomData, } impl From<[u8; 64]> for Signature { fn from(bytes: [u8; 64]) -> Signature { + let mut r_bytes = [0; 32]; + r_bytes.copy_from_slice(&bytes[0..32]); + let mut s_bytes = [0; 32]; + s_bytes.copy_from_slice(&bytes[32..64]); Signature { - bytes, + r_bytes, + s_bytes, _marker: PhantomData, } } } impl From> for [u8; 64] { - fn from(s: Signature) -> [u8; 64] { - s.bytes - } -} - -impl Signature { - pub(crate) fn from_parts(r_bytes: [u8; 32], s_bytes: [u8; 32]) -> Self { + fn from(sig: Signature) -> [u8; 64] { 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, - } + bytes[0..32].copy_from_slice(&sig.r_bytes[..]); + bytes[32..64].copy_from_slice(&sig.s_bytes[..]); + bytes } } -// These impls all only exist because of array length restrictions. - -// XXX print the type variable -impl fmt::Debug for Signature { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - //f.debug_tuple("Signature").field(&self.0[..]).finish() - f.debug_tuple("Signature").finish() - } -} - -impl Copy for Signature {} - -impl Clone for Signature { - fn clone(&self) -> Self { - let mut bytes = [0; 64]; - bytes[..].copy_from_slice(&self.bytes[..]); - Signature { - bytes, - _marker: PhantomData, - } - } -} - -impl PartialEq for Signature { - fn eq(&self, other: &Self) -> bool { - self.bytes[..] == other.bytes[..] - } -} - -impl Eq for Signature {}