1- use bytes :: Buf as _ ;
1+ pub mod opcode ;
22
33pub struct IsUnknownProtocol ;
44
@@ -9,7 +9,6 @@ pub struct IsUnknownProtocol;
99#[ derive( derive_more:: Deref ) ]
1010#[ derive( derive_more:: DerefMut ) ]
1111pub struct MarkedSignedVerified < A , B = IsUnknownProtocol > {
12- phantom_data : std:: marker:: PhantomData < B > ,
1312 signer : lib_cryptography:: public_key:: PublicKey < A > ,
1413 signature : lib_cryptography:: signature:: Signature < A > ,
1514 #[ deref]
3130 }
3231 let content: Unsigned < _ > = message. into ( ) ;
3332 Ok ( Self {
34- phantom_data : std:: marker:: PhantomData ,
3533 signer,
3634 signature,
3735 content
@@ -41,13 +39,35 @@ where
4139
4240impl < A , B > TryFrom < ( Unsigned < B > , & lib_cryptography:: secret_key:: SecretKey < A > ) > for MarkedSignedVerified < A , B >
4341where
42+ A : lib_cryptography:: AsymmetricKeyDerivationAlgorithm ,
4443 A : lib_cryptography:: AsymmetricSignatureAlgorithm {
4544 type Error = Box < dyn std:: error:: Error > ;
4645
4746 fn try_from ( value : ( Unsigned < B > , & lib_cryptography:: secret_key:: SecretKey < A > ) ) -> Result < Self , Self :: Error > {
4847 let ( unsigned, secret_key) = value;
49- let signature = A :: sign ( & secret_key. as_ref ( ) . to_vec ( ) . into_boxed_slice ( ) , & unsigned. content . to_vec ( ) . into_boxed_slice ( ) ) ?;
48+ let message: lib_bytes:: NonEmpty = unsigned. into ( ) ;
49+ let message: lib_cryptography:: message:: Message = message. into ( ) ;
50+ let signer: lib_cryptography:: public_key:: PublicKey < _ > = secret_key. public_key ( ) ;
51+ let signature: lib_cryptography:: signature:: Signature < _ > = A :: sign ( & secret_key, & message) ?;
52+ let content: Unsigned < _ > = message. into ( ) ;
53+ Ok ( Self {
54+ signer,
55+ signature,
56+ content
57+ } )
58+ }
59+ }
5060
61+ impl < A , B > TryFrom < lib_bytes:: NonEmpty > for MarkedSignedVerified < A , B >
62+ where
63+ A : lib_cryptography:: AsymmetricSetLayout ,
64+ A : lib_cryptography:: AsymmetricSignatureAlgorithm {
65+ type Error = Box < dyn std:: error:: Error > ;
66+
67+ fn try_from ( value : lib_bytes:: NonEmpty ) -> Result < Self , Self :: Error > {
68+ let out: MarkedSignedUnverified < A , B > = value. try_into ( ) ?;
69+ let out: Self = out. try_into ( ) ?;
70+ Ok ( out)
5171 }
5272}
5373
@@ -61,16 +81,13 @@ impl<A, B> Into<(lib_cryptography::signature::Signature<A>, lib_cryptography::pu
6181 }
6282}
6383
64-
65-
6684#[ derive( Debug ) ]
6785#[ derive( Clone ) ]
6886#[ derive( PartialEq ) ]
6987#[ derive( Eq ) ]
7088#[ derive( derive_more:: Deref ) ]
7189#[ derive( derive_more:: DerefMut ) ]
7290pub struct MarkedSignedUnverified < A , B = IsUnknownProtocol > {
73- phantom_data : std:: marker:: PhantomData < B > ,
7491 signer : lib_cryptography:: public_key:: PublicKey < A > ,
7592 signature : lib_cryptography:: signature:: Signature < A > ,
7693 #[ deref]
95112 let mut bytes: bytes:: Bytes = value. into ( ) ;
96113 let header_len: usize = A :: PUBLIC_KEY_LEN + A :: SIGNATURE_LEN ;
97114 if bytes. len ( ) <= header_len {
98- return Err ( <Box < dyn std:: error:: Error > >:: from ( String :: from ( "packet too short; insufficient header len " ) ) )
115+ return Err ( <Box < dyn std:: error:: Error > >:: from ( String :: from ( "packet too short; insufficient header length " ) ) )
99116 }
100117 let signer: bytes:: Bytes = bytes. split_to ( A :: PUBLIC_KEY_LEN ) ;
101118 let signer: lib_bytes:: NonEmpty = signer. try_into ( ) ?;
@@ -106,7 +123,6 @@ where
106123 let content: lib_bytes:: NonEmpty = bytes. try_into ( ) ?;
107124 let content: Unsigned < _ > = content. into ( ) ;
108125 Ok ( Self {
109- phantom_data : std:: marker:: PhantomData ,
110126 signer,
111127 signature,
112128 content
@@ -124,8 +140,17 @@ impl<A, B> Into<(lib_cryptography::signature::Signature<A>, lib_cryptography::pu
124140 }
125141}
126142
127- pub struct SignedVerified < A , B = ( ) > {
128-
143+ #[ derive( Debug ) ]
144+ #[ derive( Clone ) ]
145+ #[ derive( PartialEq ) ]
146+ #[ derive( Eq ) ]
147+ #[ derive( derive_more:: Deref ) ]
148+ #[ derive( derive_more:: DerefMut ) ]
149+ pub struct SignedVerified < A , B = IsUnknownProtocol > {
150+ signature : lib_cryptography:: signature:: Signature < A > ,
151+ #[ deref]
152+ #[ deref_mut]
153+ content : Unsigned < B >
129154}
130155
131156#[ derive( Debug ) ]
@@ -135,26 +160,12 @@ pub struct SignedVerified<A, B = ()> {
135160#[ derive( derive_more:: Deref ) ]
136161#[ derive( derive_more:: DerefMut ) ]
137162pub struct SignedUnverified < A , B = IsUnknownProtocol > {
138- phantom_data : std:: marker:: PhantomData < B > ,
139163 signature : lib_cryptography:: signature:: Signature < A > ,
140164 #[ deref]
141165 #[ deref_mut]
142166 content : Unsigned < B >
143167}
144168
145- impl < A , B > TryFrom < lib_bytes:: NonEmpty > for SignedUnverified < A , B > {
146- type Error = Box < dyn std:: error:: Error > ;
147-
148- fn try_from ( value : lib_bytes:: NonEmpty ) -> Result < Self , Self :: Error > {
149-
150- }
151- }
152-
153- // T designates the protocol the packet belongs to, () for generic, any, or unknown
154-
155-
156-
157-
158169#[ derive( Debug ) ]
159170#[ derive( Clone ) ]
160171#[ derive( PartialEq ) ]
0 commit comments