From 8ed8cac2fee9ec4f809b87fb8f5fa94d58d8b895 Mon Sep 17 00:00:00 2001 From: Arik Sosman Date: Wed, 1 Feb 2023 23:18:08 -0800 Subject: [PATCH] Implement `Debug` trait for `Scalar` type. --- src/scalar.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/scalar.rs b/src/scalar.rs index 80f54cb..e25b5a1 100644 --- a/src/scalar.rs +++ b/src/scalar.rs @@ -6,7 +6,7 @@ //! provides the `Scalar` type and related. //! -use core::fmt; +use core::{fmt, ops}; use crate::constants; @@ -23,6 +23,7 @@ use crate::constants; #[allow(missing_debug_implementations)] #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] pub struct Scalar([u8; 32]); +impl_pretty_debug!(Scalar); const MAX_RAW: [u8; 32] = [ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, @@ -107,6 +108,16 @@ impl Scalar { } } +impl ops::Index for Scalar +where + [u8]: ops::Index, +{ + type Output = <[u8] as ops::Index>::Output; + + #[inline] + fn index(&self, index: I) -> &Self::Output { &self.0[index] } +} + impl From for Scalar { fn from(value: crate::SecretKey) -> Self { Scalar(value.secret_bytes()) } }