File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -547,6 +547,7 @@ macro_rules! sig_variant_impl {
547547 $sig_aggr_in_group: ident,
548548 ) => {
549549 /// Secret Key
550+ #[ repr( transparent) ]
550551 #[ derive( Default , Debug , Clone , Zeroize ) ]
551552 #[ zeroize( drop) ]
552553 pub struct SecretKey {
@@ -775,6 +776,29 @@ macro_rules! sig_variant_impl {
775776 }
776777 }
777778
779+ // From<by-value> traits are not provided to discourage duplication
780+ // of the secret key material.
781+ impl <' a> From <& ' a SecretKey > for & ' a blst_scalar {
782+ fn from( sk: & ' a SecretKey ) -> Self {
783+ unsafe {
784+ transmute:: <& SecretKey , Self >( sk)
785+ }
786+ }
787+ }
788+
789+ impl <' a> core:: convert:: TryFrom <& ' a blst_scalar> for & ' a SecretKey {
790+ type Error = BLST_ERROR ;
791+
792+ fn try_from( sk: & ' a blst_scalar) -> Result <Self , Self :: Error > {
793+ unsafe {
794+ if !blst_sk_check( sk) {
795+ return Err ( BLST_ERROR :: BLST_BAD_ENCODING ) ;
796+ }
797+ Ok ( transmute:: <& blst_scalar, Self >( sk) )
798+ }
799+ }
800+ }
801+
778802 #[ repr( transparent) ]
779803 #[ derive( Default , Debug , Clone , Copy ) ]
780804 pub struct PublicKey {
You can’t perform that action at this time.
0 commit comments