Implement `Debug` trait for `Scalar` type.

This commit is contained in:
Arik Sosman 2023-02-01 23:18:08 -08:00
parent 65eb166c09
commit 8ed8cac2fe
No known key found for this signature in database
GPG Key ID: F4FB5A3366C4D92E
1 changed files with 12 additions and 1 deletions

View File

@ -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<I> ops::Index<I> for Scalar
where
[u8]: ops::Index<I>,
{
type Output = <[u8] as ops::Index<I>>::Output;
#[inline]
fn index(&self, index: I) -> &Self::Output { &self.0[index] }
}
impl From<crate::SecretKey> for Scalar {
fn from(value: crate::SecretKey) -> Self { Scalar(value.secret_bytes()) }
}