@@ -15,23 +15,38 @@ pub trait Signer: Update {
1515 #[ allow( missing_docs) ]
1616 type FinishError : From < Self :: Error > ;
1717
18+ /// The unprotected header type
19+ type Unprotected ;
20+
21+ /// The protected header type
22+ type Protected ;
23+
1824 /// Finish processing payload and create the signature.
19- fn finish ( self , rng : impl ' static + RngCore ) -> Result < Signature , Self :: FinishError > ;
25+ fn finish (
26+ self ,
27+ rng : impl ' static + RngCore ,
28+ ) -> Result < Signature < Self :: Unprotected , Self :: Protected > , Self :: FinishError > ;
2029}
2130
2231/// A signature creation key
23- pub trait SigningKey < ' a > {
32+ pub trait SigningKey < ' a , U = Unprotected , P = Protected < U > > {
2433 #[ allow( missing_docs) ]
2534 type StartError : From < <Self :: Signer as Update >:: Error > ;
2635
36+ /// The unprotected header type
37+ type Unprotected ;
38+
39+ /// The protected header type
40+ type Protected ;
41+
2742 /// The state object used during signing.
28- type Signer : Signer ;
43+ type Signer : Signer < Unprotected = Self :: Unprotected , Protected = Self :: Protected > ;
2944
3045 /// Begin the signature creation process.
3146 fn sign (
3247 & ' a self ,
33- prot : Option < Protected > ,
34- head : Option < Unprotected > ,
48+ prot : Option < Self :: Protected > ,
49+ head : Option < Self :: Unprotected > ,
3550 ) -> Result < Self :: Signer , Self :: StartError > ;
3651}
3752
@@ -98,26 +113,31 @@ where
98113 }
99114}
100115
101- impl < ' a , T : VerifyingKey < ' a , & ' a Signature > > VerifyingKey < ' a , & ' a Flattened > for T
116+ impl < ' a , T , U , P > VerifyingKey < ' a , & ' a Flattened < U , P > > for T
102117where
118+ T : VerifyingKey < ' a , & ' a Signature < U , P > > ,
103119 <T :: Verifier as Verifier < ' a > >:: FinishError : Default ,
104120{
105121 type StartError = T :: StartError ;
106122 type Verifier = Vec < T :: Verifier > ;
107123
108- fn verify ( & ' a self , flattened : & ' a Flattened ) -> Result < Self :: Verifier , Self :: StartError > {
124+ fn verify (
125+ & ' a self ,
126+ flattened : & ' a Flattened < U , P > ,
127+ ) -> Result < Self :: Verifier , Self :: StartError > {
109128 Ok ( vec ! [ self . verify( & flattened. signature) ?] )
110129 }
111130}
112131
113- impl < ' a , T : VerifyingKey < ' a , & ' a Signature > > VerifyingKey < ' a , & ' a General > for T
132+ impl < ' a , T , U , P > VerifyingKey < ' a , & ' a General < U , P > > for T
114133where
134+ T : VerifyingKey < ' a , & ' a Signature < U , P > > ,
115135 <T :: Verifier as Verifier < ' a > >:: FinishError : Default ,
116136{
117137 type StartError = T :: StartError ;
118138 type Verifier = Vec < T :: Verifier > ;
119139
120- fn verify ( & ' a self , general : & ' a General ) -> Result < Self :: Verifier , Self :: StartError > {
140+ fn verify ( & ' a self , general : & ' a General < U , P > ) -> Result < Self :: Verifier , Self :: StartError > {
121141 general
122142 . signatures
123143 . iter ( )
@@ -126,17 +146,17 @@ where
126146 }
127147}
128148
129- impl < ' a , T , V , E > VerifyingKey < ' a , & ' a Jws > for T
149+ impl < ' a , T , V , E , U , P > VerifyingKey < ' a , & ' a Jws < U , P > > for T
130150where
131- T : VerifyingKey < ' a , & ' a Flattened , Verifier = V , StartError = E > ,
132- T : VerifyingKey < ' a , & ' a General , Verifier = V , StartError = E > ,
151+ T : VerifyingKey < ' a , & ' a Flattened < U , P > , Verifier = V , StartError = E > ,
152+ T : VerifyingKey < ' a , & ' a General < U , P > , Verifier = V , StartError = E > ,
133153 E : From < V :: Error > ,
134154 V : Verifier < ' a > ,
135155{
136156 type StartError = E ;
137157 type Verifier = V ;
138158
139- fn verify ( & ' a self , jws : & ' a Jws ) -> Result < Self :: Verifier , Self :: StartError > {
159+ fn verify ( & ' a self , jws : & ' a Jws < U , P > ) -> Result < Self :: Verifier , Self :: StartError > {
140160 match jws {
141161 Jws :: General ( general) => self . verify ( general) ,
142162 Jws :: Flattened ( flattened) => self . verify ( flattened) ,
0 commit comments