@@ -186,3 +186,67 @@ fn pubkey_hash() {
186186 assert_eq ! ( hash( & vk1) , hash( & vk1) ) ;
187187 assert_ne ! ( hash( & vk1) , hash( & vk2) ) ;
188188}
189+
190+ #[ platform:: test]
191+ fn private_key_from ( ) {
192+ let raw = hex ! ( "78958e49abad190be2d51bab73af07f87682cfcd65cceedd27e4b2a94bfd8537" ) ;
193+ let key = PrivateKey :: from ( raw) ;
194+
195+ assert_eq ! ( * key. to_bytes( ) , raw) ;
196+ }
197+
198+ #[ platform:: test]
199+ fn private_key_try_from_array_of_u8 ( ) {
200+ let raw = hex ! ( "78958e49abad190be2d51bab73af07f87682cfcd65cceedd27e4b2a94bfd8537" ) ;
201+ let key = PrivateKey :: try_from ( raw. as_ref ( ) ) . unwrap ( ) ;
202+
203+ assert_eq ! ( * key. to_bytes( ) , raw) ;
204+
205+ let outcome = PrivateKey :: try_from ( b"<too_small>" . as_ref ( ) ) ;
206+
207+ assert_eq ! ( outcome, Err ( CryptoError :: DataSize ) ) ;
208+ }
209+
210+ #[ platform:: test]
211+ fn private_key_try_from_serde_bytes ( ) {
212+ let raw = hex ! ( "78958e49abad190be2d51bab73af07f87682cfcd65cceedd27e4b2a94bfd8537" ) ;
213+ let key = PrivateKey :: try_from ( serde_bytes:: Bytes :: new ( & raw ) ) . unwrap ( ) ;
214+
215+ assert_eq ! ( * key. to_bytes( ) , raw) ;
216+
217+ let outcome = PrivateKey :: try_from ( serde_bytes:: Bytes :: new ( b"<too_small>" ) ) ;
218+
219+ assert_eq ! ( outcome, Err ( CryptoError :: DataSize ) ) ;
220+ }
221+
222+ #[ platform:: test]
223+ fn publickey_key_try_from_static_array_of_u8 ( ) {
224+ let raw = hex ! ( "78958e49abad190be2d51bab73af07f87682cfcd65cceedd27e4b2a94bfd8537" ) ;
225+ let key = PublicKey :: from ( raw) ;
226+
227+ assert_eq ! ( key. as_ref( ) , raw) ;
228+ }
229+
230+ #[ platform:: test]
231+ fn publickey_key_try_from_array_of_u8 ( ) {
232+ let raw = hex ! ( "78958e49abad190be2d51bab73af07f87682cfcd65cceedd27e4b2a94bfd8537" ) ;
233+ let key = PublicKey :: try_from ( raw. as_ref ( ) ) . unwrap ( ) ;
234+
235+ assert_eq ! ( key. as_ref( ) , raw) ;
236+
237+ let outcome = PublicKey :: try_from ( b"<too_small>" . as_ref ( ) ) ;
238+
239+ assert_eq ! ( outcome, Err ( CryptoError :: DataSize ) ) ;
240+ }
241+
242+ #[ platform:: test]
243+ fn publickey_key_try_from_serde_bytes ( ) {
244+ let raw = hex ! ( "78958e49abad190be2d51bab73af07f87682cfcd65cceedd27e4b2a94bfd8537" ) ;
245+ let key = PublicKey :: try_from ( serde_bytes:: Bytes :: new ( & raw ) ) . unwrap ( ) ;
246+
247+ assert_eq ! ( key. as_ref( ) , raw) ;
248+
249+ let outcome = PublicKey :: try_from ( serde_bytes:: Bytes :: new ( b"<too_small>" ) ) ;
250+
251+ assert_eq ! ( outcome, Err ( CryptoError :: DataSize ) ) ;
252+ }
0 commit comments