From 39920186b337f05aac338acefc62607f8067cc7a Mon Sep 17 00:00:00 2001 From: str4d Date: Tue, 26 Sep 2017 15:59:50 +0100 Subject: [PATCH] Force public structures to implement Debug Closes #23. --- src/bls12_381/ec.rs | 30 ++++++++++++++++++++++++++++-- src/bls12_381/mod.rs | 1 + src/lib.rs | 4 ++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/bls12_381/ec.rs b/src/bls12_381/ec.rs index b7041c33e..bc00cbcc6 100644 --- a/src/bls12_381/ec.rs +++ b/src/bls12_381/ec.rs @@ -584,6 +584,7 @@ macro_rules! curve_impl { pub mod g1 { use rand::{Rand, Rng}; + use std::fmt; use super::g2::G2Affine; use super::super::{Bls12, Fq, Fr, FrRepr, FqRepr, Fq12}; use ::{CurveProjective, CurveAffine, PrimeField, SqrtField, PrimeFieldRepr, Field, BitIterator, EncodedPoint, GroupDecodingError, Engine}; @@ -611,6 +612,12 @@ pub mod g1 { } } + impl fmt::Debug for G1Uncompressed { + fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> { + self.0[..].fmt(formatter) + } + } + impl EncodedPoint for G1Uncompressed { type Affine = G1Affine; @@ -713,6 +720,12 @@ pub mod g1 { } } + impl fmt::Debug for G1Compressed { + fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> { + self.0[..].fmt(formatter) + } + } + impl EncodedPoint for G1Compressed { type Affine = G1Affine; @@ -879,7 +892,7 @@ pub mod g1 { } } - #[derive(Clone)] + #[derive(Clone, Debug)] pub struct G1Prepared(pub(crate) G1Affine); impl G1Prepared { @@ -1137,6 +1150,7 @@ pub mod g1 { pub mod g2 { use rand::{Rand, Rng}; + use std::fmt; use super::super::{Bls12, Fq2, Fr, Fq, FrRepr, FqRepr, Fq12}; use super::g1::G1Affine; use ::{CurveProjective, CurveAffine, PrimeField, SqrtField, PrimeFieldRepr, Field, BitIterator, EncodedPoint, GroupDecodingError, Engine}; @@ -1164,6 +1178,12 @@ pub mod g2 { } } + impl fmt::Debug for G2Uncompressed { + fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> { + self.0[..].fmt(formatter) + } + } + impl EncodedPoint for G2Uncompressed { type Affine = G2Affine; @@ -1278,6 +1298,12 @@ pub mod g2 { } } + impl fmt::Debug for G2Compressed { + fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> { + self.0[..].fmt(formatter) + } + } + impl EncodedPoint for G2Compressed { type Affine = G2Affine; @@ -1459,7 +1485,7 @@ pub mod g2 { } } - #[derive(Clone)] + #[derive(Clone, Debug)] pub struct G2Prepared { pub(crate) coeffs: Vec<(Fq2, Fq2, Fq2)>, pub(crate) infinity: bool diff --git a/src/bls12_381/mod.rs b/src/bls12_381/mod.rs index 28af9d8a0..2c55c2225 100644 --- a/src/bls12_381/mod.rs +++ b/src/bls12_381/mod.rs @@ -21,6 +21,7 @@ use super::{Engine, CurveAffine, Field, BitIterator}; const BLS_X: u64 = 0xd201000000010000; const BLS_X_IS_NEGATIVE: bool = true; +#[derive(Debug)] pub struct Bls12; impl Engine for Bls12 { diff --git a/src/lib.rs b/src/lib.rs index 9798d0df4..8bbd2f6c3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,6 +13,9 @@ #![cfg_attr(feature = "clippy", allow(too_many_arguments))] #![cfg_attr(feature = "clippy", allow(unreadable_literal))] +// Force public structures to implement Debug +#![deny(missing_debug_implementations)] + // The compiler provides `test` (on nightly) for benchmarking tools, but // it's hidden behind a feature flag. Enable it if we're testing. #![cfg_attr(test, feature(test))] @@ -563,6 +566,7 @@ pub trait PrimeField: Field fn root_of_unity() -> Self; } +#[derive(Debug)] pub struct BitIterator { t: E, n: usize