17
17
//!
18
18
19
19
use core:: convert:: TryFrom ;
20
- use core:: ops:: BitXor ;
20
+ use core:: ops:: { self , BitXor } ;
21
21
use core:: { fmt, ptr, str} ;
22
22
23
23
#[ cfg( feature = "serde" ) ]
@@ -28,7 +28,7 @@ use crate::ffi::{self, CPtr};
28
28
#[ cfg( all( feature = "global-context" , feature = "rand-std" ) ) ]
29
29
use crate :: schnorr;
30
30
use crate :: Error :: { self , InvalidPublicKey , InvalidPublicKeySum , InvalidSecretKey } ;
31
- use crate :: { constants, from_hex, impl_array_newtype , Scalar , Secp256k1 , Signing , Verification } ;
31
+ use crate :: { constants, from_hex, Scalar , Secp256k1 , Signing , Verification } ;
32
32
#[ cfg( feature = "global-context" ) ]
33
33
use crate :: { ecdsa, Message , SECP256K1 } ;
34
34
#[ cfg( feature = "bitcoin-hashes" ) ]
@@ -58,9 +58,70 @@ use crate::{hashes, ThirtyTwoByteHash};
58
58
/// [`cbor`]: https://docs.rs/cbor
59
59
#[ derive( Copy , Clone ) ]
60
60
pub struct SecretKey ( [ u8 ; constants:: SECRET_KEY_SIZE ] ) ;
61
- impl_array_newtype ! ( SecretKey , u8 , constants:: SECRET_KEY_SIZE ) ;
62
61
impl_display_secret ! ( SecretKey ) ;
63
62
63
+ impl PartialEq for SecretKey {
64
+ #[ inline]
65
+ fn eq ( & self , other : & Self ) -> bool {
66
+ self [ ..] == other[ ..]
67
+ }
68
+ }
69
+
70
+ impl Eq for SecretKey { }
71
+
72
+ impl core:: hash:: Hash for SecretKey {
73
+ fn hash < H : core:: hash:: Hasher > ( & self , state : & mut H ) {
74
+ self [ ..] . hash ( state)
75
+ }
76
+ }
77
+
78
+ impl PartialOrd for SecretKey {
79
+ #[ inline]
80
+ fn partial_cmp ( & self , other : & SecretKey ) -> Option < core:: cmp:: Ordering > {
81
+ self [ ..] . partial_cmp ( & other[ ..] )
82
+ }
83
+ }
84
+
85
+ impl Ord for SecretKey {
86
+ #[ inline]
87
+ fn cmp ( & self , other : & SecretKey ) -> core:: cmp:: Ordering {
88
+ self [ ..] . cmp ( & other[ ..] )
89
+ }
90
+ }
91
+
92
+ impl AsRef < [ u8 ; constants:: SECRET_KEY_SIZE ] > for SecretKey {
93
+ /// Gets a reference to the underlying array
94
+ #[ inline]
95
+ fn as_ref ( & self ) -> & [ u8 ; constants:: SECRET_KEY_SIZE ] {
96
+ let & SecretKey ( ref dat) = self ;
97
+ dat
98
+ }
99
+ }
100
+
101
+ impl < I > ops:: Index < I > for SecretKey
102
+ where
103
+ [ u8 ] : ops:: Index < I > ,
104
+ {
105
+ type Output = <[ u8 ] as ops:: Index < I > >:: Output ;
106
+
107
+ #[ inline]
108
+ fn index ( & self , index : I ) -> & Self :: Output { & self . 0 [ index] }
109
+ }
110
+
111
+ impl ffi:: CPtr for SecretKey {
112
+ type Target = u8 ;
113
+
114
+ fn as_c_ptr ( & self ) -> * const Self :: Target {
115
+ let & SecretKey ( ref dat) = self ;
116
+ dat. as_ptr ( )
117
+ }
118
+
119
+ fn as_mut_c_ptr ( & mut self ) -> * mut Self :: Target {
120
+ let & mut SecretKey ( ref mut dat) = self ;
121
+ dat. as_mut_ptr ( )
122
+ }
123
+ }
124
+
64
125
impl str:: FromStr for SecretKey {
65
126
type Err = Error ;
66
127
fn from_str ( s : & str ) -> Result < SecretKey , Error > {
0 commit comments