Skip to content

Commit

Permalink
elliptic-curve: add missing Debug impls (#1675)
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov authored Sep 27, 2024
1 parent 9c7605a commit badd347
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 2 deletions.
14 changes: 13 additions & 1 deletion elliptic-curve/src/ecdh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::{
point::AffineCoordinates, AffinePoint, Curve, CurveArithmetic, FieldBytes, NonZeroScalar,
ProjectivePoint, PublicKey,
};
use core::borrow::Borrow;
use core::{borrow::Borrow, fmt};
use digest::{crypto_common::BlockSizeUser, Digest};
use group::Curve as _;
use hkdf::{hmac::SimpleHmac, Hkdf};
Expand Down Expand Up @@ -97,6 +97,12 @@ where
scalar: NonZeroScalar<C>,
}

impl<C: CurveArithmetic> fmt::Debug for EphemeralSecret<C> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("EphemeralSecret").finish_non_exhaustive()
}
}

impl<C> EphemeralSecret<C>
where
C: CurveArithmetic,
Expand Down Expand Up @@ -157,6 +163,12 @@ pub struct SharedSecret<C: Curve> {
secret_bytes: FieldBytes<C>,
}

impl<C: Curve> fmt::Debug for SharedSecret<C> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("SharedSecret").finish_non_exhaustive()
}
}

impl<C: Curve> SharedSecret<C> {
/// Create a new [`SharedSecret`] from an [`AffinePoint`] for this curve.
#[inline]
Expand Down
1 change: 1 addition & 0 deletions elliptic-curve/src/hash2curve/hash2field/expand_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub trait Expander {
/// Implements [section 5.4.3 of `draft-irtf-cfrg-hash-to-curve-13`][dst].
///
/// [dst]: https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hash-to-curve-13#section-5.4.3
#[derive(Debug)]
pub(crate) enum Domain<'a, L>
where
L: ArraySize + IsLess<U256>,
Expand Down
2 changes: 2 additions & 0 deletions elliptic-curve/src/hash2curve/hash2field/expand_msg/xmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use digest::{
/// - `len_in_bytes == 0`
/// - `len_in_bytes > u16::MAX`
/// - `len_in_bytes > 255 * HashT::OutputSize`
#[derive(Debug)]
pub struct ExpandMsgXmd<HashT>(PhantomData<HashT>)
where
HashT: BlockSizeUser + Default + FixedOutput + HashMarker,
Expand Down Expand Up @@ -87,6 +88,7 @@ where
}

/// [`Expander`] type for [`ExpandMsgXmd`].
#[derive(Debug)]
pub struct ExpanderXmd<'a, HashT>
where
HashT: BlockSizeUser + Default + FixedOutput + HashMarker,
Expand Down
13 changes: 13 additions & 0 deletions elliptic-curve/src/hash2curve/hash2field/expand_msg/xof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use super::{Domain, ExpandMsg, Expander};
use crate::{Error, Result};
use core::fmt;
use digest::{ExtendableOutput, Update, XofReader};
use hybrid_array::typenum::U32;

Expand All @@ -18,6 +19,18 @@ where
reader: <HashT as ExtendableOutput>::Reader,
}

impl<HashT> fmt::Debug for ExpandMsgXof<HashT>
where
HashT: Default + ExtendableOutput + Update,
<HashT as ExtendableOutput>::Reader: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ExpandMsgXof")
.field("reader", &self.reader)
.finish()
}
}

/// ExpandMsgXof implements `expand_message_xof` for the [`ExpandMsg`] trait
impl<'a, HashT> ExpandMsg<'a> for ExpandMsgXof<HashT>
where
Expand Down
1 change: 1 addition & 0 deletions elliptic-curve/src/hash2curve/isogeny.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use ff::Field;
use hybrid_array::{typenum::Unsigned, Array, ArraySize};

/// The coefficients for mapping from one isogenous curve to another
#[derive(Debug)]
pub struct IsogenyCoefficients<F: Field + AddAssign + Mul<Output = F>> {
/// The coefficients for the x numerator
pub xnum: &'static [F],
Expand Down
1 change: 1 addition & 0 deletions elliptic-curve/src/hash2curve/osswu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use subtle::ConditionallySelectable;
use subtle::ConstantTimeEq;

/// The Optimized Simplified Shallue-van de Woestijne-Ulas parameters
#[derive(Debug)]
pub struct OsswuMapParams<F>
where
F: Field,
Expand Down
1 change: 1 addition & 0 deletions elliptic-curve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
clippy::panic,
clippy::panic_in_result_fn,
clippy::unwrap_used,
missing_debug_implementations,
missing_docs,
rust_2018_idioms,
unused_lifetimes,
Expand Down
2 changes: 1 addition & 1 deletion elliptic-curve/src/point/non_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{CurveArithmetic, NonZeroScalar, Scalar};
///
/// In the context of ECC, it's useful for ensuring that certain arithmetic
/// cannot result in the identity point.
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct NonIdentity<P> {
point: P,
}
Expand Down
7 changes: 7 additions & 0 deletions elliptic-curve/src/scalar/blinded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use super::Scalar;
use crate::{ops::Invert, CurveArithmetic};
use core::fmt;
use group::ff::Field;
use rand_core::CryptoRngCore;
use subtle::CtOption;
Expand All @@ -26,6 +27,12 @@ where
mask: Scalar<C>,
}

impl<C: CurveArithmetic> fmt::Debug for BlindedScalar<C> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("BlindedScalar").finish_non_exhaustive()
}
}

impl<C> BlindedScalar<C>
where
C: CurveArithmetic,
Expand Down
6 changes: 6 additions & 0 deletions elliptic-curve/src/scalar/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ where
scalar: Scalar<C>,
}

impl<C: CurveArithmetic> fmt::Debug for NonZeroScalar<C> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("NonZeroScalar").finish_non_exhaustive()
}
}

impl<C> NonZeroScalar<C>
where
C: CurveArithmetic,
Expand Down

0 comments on commit badd347

Please sign in to comment.