File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,11 +4,7 @@ use p256::{
44 elliptic_curve:: { ecdh, sec1:: ToCompactEncodedPoint , DecompactPoint } ,
55 FieldBytes ,
66} ;
7- use std:: {
8- convert:: TryFrom ,
9- hash:: { Hash , Hasher } ,
10- ops:: Deref ,
11- } ;
7+ use std:: { hash:: Hasher , ops:: Deref } ;
128
139#[ derive( Debug , Clone ) ]
1410pub struct PublicKey ( pub ( crate ) p256:: PublicKey ) ;
Original file line number Diff line number Diff line change 11use crate :: * ;
2- use std:: {
3- convert:: TryFrom ,
4- hash:: { Hash , Hasher } ,
5- } ;
2+ use std:: hash:: Hasher ;
63
74#[ derive( Debug , Clone ) ]
85pub struct PublicKey ( pub ( crate ) ed25519_compact:: PublicKey ) ;
@@ -100,9 +97,10 @@ impl Keypair {
10097
10198impl signature:: Signature for Signature {
10299 fn from_bytes ( input : & [ u8 ] ) -> std:: result:: Result < Self , signature:: Error > {
103- let signature =
104- ed25519_compact:: Signature :: try_from ( input) . map_err ( signature:: Error :: from_source) ?;
105- Ok ( Signature ( signature) )
100+ Ok ( Signature (
101+ ed25519_compact:: Signature :: from_slice ( input)
102+ . map_err ( |_| signature:: Error :: default ( ) ) ?,
103+ ) )
106104 }
107105
108106 fn as_bytes ( & self ) -> & [ u8 ] {
@@ -140,8 +138,7 @@ impl signature::Signer<Signature> for Keypair {
140138
141139impl Signature {
142140 pub fn from_bytes ( bytes : & [ u8 ] ) -> Result < Self > {
143- let signature = ed25519_compact:: Signature :: try_from ( bytes) ?;
144- Ok ( Signature ( signature) )
141+ Ok ( Signature ( ed25519_compact:: Signature :: from_slice ( bytes) ?) )
145142 }
146143
147144 pub fn to_vec ( & self ) -> Vec < u8 > {
@@ -153,8 +150,9 @@ impl TryFrom<&[u8]> for Signature {
153150 type Error = Error ;
154151
155152 fn try_from ( input : & [ u8 ] ) -> Result < Self > {
156- let signature = ed25519_compact:: Signature :: try_from ( input) ?;
157- Ok ( Signature ( signature) )
153+ ed25519_compact:: Signature :: from_slice ( input)
154+ . map ( Signature )
155+ . map_err ( Error :: from)
158156 }
159157}
160158
Original file line number Diff line number Diff line change 33//! since a client will need to be able to parse and use a public key from any
44//! keypair.
55use crate :: * ;
6- use std:: { convert:: TryFrom , hash:: Hash } ;
76
87///Verify a given message against a given signature slice. Public keys are
98///expected to implemt this trait to verify signed messages.
Original file line number Diff line number Diff line change 11use crate :: * ;
22use base64:: { engine:: general_purpose:: STANDARD , Engine } ;
33use k256:: { ecdsa, elliptic_curve:: sec1:: ToEncodedPoint } ;
4- use std:: {
5- convert:: TryFrom ,
6- hash:: { Hash , Hasher } ,
7- } ;
4+ use std:: hash:: Hasher ;
85use thiserror:: Error ;
96
107#[ derive( Debug , Clone ) ]
You can’t perform that action at this time.
0 commit comments