diff --git a/mod.rs b/mod.rs index db100c4..8d2aa02 100644 --- a/mod.rs +++ b/mod.rs @@ -4,6 +4,9 @@ pub mod keygen; mod serde_impl; use self::keygen::{Commitment, Poly}; + +use std::fmt; + use byteorder::{BigEndian, ByteOrder}; use init_with::InitWith; use pairing::{CurveAffine, CurveProjective, Engine, Field, PrimeField}; @@ -11,6 +14,7 @@ use rand::{ChaChaRng, OsRng, Rng, SeedableRng}; use ring::digest; use self::error::{ErrorKind, Result}; +use fmt::HexBytes; /// The number of words (`u32`) in a ChaCha RNG seed. const CHACHA_RNG_SEED_SIZE: usize = 8; @@ -56,12 +60,25 @@ impl PublicKey { let w = hash_g1_g2::(u, &v).into_affine().mul(r); Ciphertext(u, v, w) } + + /// Returns a byte string representation of the public key. + pub fn to_bytes(&self) -> Vec { + self.0.into_affine().into_compressed().as_ref().to_vec() + } } /// A signature, or a signature share. -#[derive(Clone, Debug, PartialOrd)] +#[derive(Clone, PartialOrd)] pub struct Signature(E::G2); +impl fmt::Debug for Signature { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let uncomp = self.0.into_affine().into_uncompressed(); + let bytes = uncomp.as_ref(); + write!(f, "{:?}", HexBytes(bytes)) + } +} + impl PartialEq for Signature { fn eq(&self, other: &Signature) -> bool { self.0 == other.0 @@ -73,8 +90,8 @@ impl Signature { let uncomp = self.0.into_affine().into_uncompressed(); let bytes = uncomp.as_ref(); let xor_bytes: u8 = bytes.iter().fold(0, |result, byte| result ^ byte); - let parity = 0 == xor_bytes % 2; - debug!("Signature: {:?}, output: {}", bytes, parity); + let parity = 0 != xor_bytes % 2; + debug!("Signature: {:?}, output: {}", HexBytes(bytes), parity); parity } }