Skip to content

Commit 6e33f51

Browse files
committed
elliptic-curve: add missing Debug impls
1 parent 9c7605a commit 6e33f51

File tree

10 files changed

+46
-2
lines changed

10 files changed

+46
-2
lines changed

elliptic-curve/src/ecdh.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::{
3030
point::AffineCoordinates, AffinePoint, Curve, CurveArithmetic, FieldBytes, NonZeroScalar,
3131
ProjectivePoint, PublicKey,
3232
};
33-
use core::borrow::Borrow;
33+
use core::{borrow::Borrow, fmt};
3434
use digest::{crypto_common::BlockSizeUser, Digest};
3535
use group::Curve as _;
3636
use hkdf::{hmac::SimpleHmac, Hkdf};
@@ -97,6 +97,12 @@ where
9797
scalar: NonZeroScalar<C>,
9898
}
9999

100+
impl<C: CurveArithmetic> fmt::Debug for EphemeralSecret<C> {
101+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
102+
f.debug_struct("EphemeralSecret").finish_non_exhaustive()
103+
}
104+
}
105+
100106
impl<C> EphemeralSecret<C>
101107
where
102108
C: CurveArithmetic,
@@ -157,6 +163,12 @@ pub struct SharedSecret<C: Curve> {
157163
secret_bytes: FieldBytes<C>,
158164
}
159165

166+
impl<C: Curve> fmt::Debug for SharedSecret<C> {
167+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
168+
f.debug_struct("SharedSecret").finish_non_exhaustive()
169+
}
170+
}
171+
160172
impl<C: Curve> SharedSecret<C> {
161173
/// Create a new [`SharedSecret`] from an [`AffinePoint`] for this curve.
162174
#[inline]

elliptic-curve/src/hash2curve/hash2field/expand_msg.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub trait Expander {
4343
/// Implements [section 5.4.3 of `draft-irtf-cfrg-hash-to-curve-13`][dst].
4444
///
4545
/// [dst]: https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hash-to-curve-13#section-5.4.3
46+
#[derive(Debug)]
4647
pub(crate) enum Domain<'a, L>
4748
where
4849
L: ArraySize + IsLess<U256>,

elliptic-curve/src/hash2curve/hash2field/expand_msg/xmd.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use digest::{
2020
/// - `len_in_bytes == 0`
2121
/// - `len_in_bytes > u16::MAX`
2222
/// - `len_in_bytes > 255 * HashT::OutputSize`
23+
#[derive(Debug)]
2324
pub struct ExpandMsgXmd<HashT>(PhantomData<HashT>)
2425
where
2526
HashT: BlockSizeUser + Default + FixedOutput + HashMarker,
@@ -87,6 +88,7 @@ where
8788
}
8889

8990
/// [`Expander`] type for [`ExpandMsgXmd`].
91+
#[derive(Debug)]
9092
pub struct ExpanderXmd<'a, HashT>
9193
where
9294
HashT: BlockSizeUser + Default + FixedOutput + HashMarker,

elliptic-curve/src/hash2curve/hash2field/expand_msg/xof.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use super::{Domain, ExpandMsg, Expander};
44
use crate::{Error, Result};
5+
use core::fmt;
56
use digest::{ExtendableOutput, Update, XofReader};
67
use hybrid_array::typenum::U32;
78

@@ -18,6 +19,18 @@ where
1819
reader: <HashT as ExtendableOutput>::Reader,
1920
}
2021

22+
impl<HashT> fmt::Debug for ExpandMsgXof<HashT>
23+
where
24+
HashT: Default + ExtendableOutput + Update,
25+
<HashT as ExtendableOutput>::Reader: fmt::Debug,
26+
{
27+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28+
f.debug_struct("ExpandMsgXof")
29+
.field("reader", &self.reader)
30+
.finish()
31+
}
32+
}
33+
2134
/// ExpandMsgXof implements `expand_message_xof` for the [`ExpandMsg`] trait
2235
impl<'a, HashT> ExpandMsg<'a> for ExpandMsgXof<HashT>
2336
where

elliptic-curve/src/hash2curve/isogeny.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use ff::Field;
77
use hybrid_array::{typenum::Unsigned, Array, ArraySize};
88

99
/// The coefficients for mapping from one isogenous curve to another
10+
#[derive(Debug)]
1011
pub struct IsogenyCoefficients<F: Field + AddAssign + Mul<Output = F>> {
1112
/// The coefficients for the x numerator
1213
pub xnum: &'static [F],

elliptic-curve/src/hash2curve/osswu.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use subtle::ConditionallySelectable;
88
use subtle::ConstantTimeEq;
99

1010
/// The Optimized Simplified Shallue-van de Woestijne-Ulas parameters
11+
#[derive(Debug)]
1112
pub struct OsswuMapParams<F>
1213
where
1314
F: Field,

elliptic-curve/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
clippy::panic,
1919
clippy::panic_in_result_fn,
2020
clippy::unwrap_used,
21+
missing_debug_implementations,
2122
missing_docs,
2223
rust_2018_idioms,
2324
unused_lifetimes,

elliptic-curve/src/point/non_identity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::{CurveArithmetic, NonZeroScalar, Scalar};
1717
///
1818
/// In the context of ECC, it's useful for ensuring that certain arithmetic
1919
/// cannot result in the identity point.
20-
#[derive(Clone, Copy)]
20+
#[derive(Clone, Copy, Debug)]
2121
pub struct NonIdentity<P> {
2222
point: P,
2323
}

elliptic-curve/src/scalar/blinded.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use super::Scalar;
44
use crate::{ops::Invert, CurveArithmetic};
5+
use core::fmt;
56
use group::ff::Field;
67
use rand_core::CryptoRngCore;
78
use subtle::CtOption;
@@ -26,6 +27,12 @@ where
2627
mask: Scalar<C>,
2728
}
2829

30+
impl<C: CurveArithmetic> fmt::Debug for BlindedScalar<C> {
31+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32+
f.debug_struct("BlindedScalar").finish_non_exhaustive()
33+
}
34+
}
35+
2936
impl<C> BlindedScalar<C>
3037
where
3138
C: CurveArithmetic,

elliptic-curve/src/scalar/nonzero.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ where
3636
scalar: Scalar<C>,
3737
}
3838

39+
impl<C: CurveArithmetic> fmt::Debug for NonZeroScalar<C> {
40+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41+
f.debug_struct("NonZeroScalar").finish_non_exhaustive()
42+
}
43+
}
44+
3945
impl<C> NonZeroScalar<C>
4046
where
4147
C: CurveArithmetic,

0 commit comments

Comments
 (0)