Skip to content

Commit cdd7d41

Browse files
authored
Add AsRef<[u8]> and Into<[u8; N]> for ECPublicKey (#33)
* Add AsRef<[u8]> and Into<[u8; N]> for ECPublicKey * add as_ref/to_bytes to ecc::PublicKey * remove privatekey internal access, add Eq to CxError
1 parent 72634bd commit cdd7d41

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/ecc.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub enum CurvesId {
2525
Invalid,
2626
}
2727

28+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
2829
pub enum CxError {
2930
Carry,
3031
Locked,
@@ -165,6 +166,7 @@ pub struct ECPublicKey<const S: usize, const TY: char> {
165166
pubkey: [u8; S],
166167
}
167168

169+
/// Create a default (empty/invalid) private key object
168170
impl<const N: usize, const TY: char> Default for ECPrivateKey<N, TY> {
169171
fn default() -> ECPrivateKey<N, TY> {
170172
ECPrivateKey {
@@ -347,6 +349,20 @@ impl<const P: usize, const TY: char> ECPublicKey<P, TY> {
347349
}
348350
}
349351

352+
/// Access public key value by reference
353+
impl<const P: usize, const TY: char> AsRef<[u8]> for ECPublicKey<P, TY> {
354+
fn as_ref(&self) -> &[u8] {
355+
&self.pubkey
356+
}
357+
}
358+
359+
/// Access public key value as array
360+
impl<const P: usize, const TY: char> From<ECPublicKey<P, TY>> for [u8; P] {
361+
fn from(p: ECPublicKey<P, TY>) -> Self {
362+
p.pubkey
363+
}
364+
}
365+
350366
/// Specific signature verification for Weierstrass curves, which
351367
/// all use ECDSA.
352368
impl<const P: usize> ECPublicKey<P, 'W'> {

0 commit comments

Comments
 (0)