@@ -5,7 +5,6 @@ use bitcoin::consensus::encode::Decodable;
55use bitcoin:: consensus:: Encodable ;
66use url:: Url ;
77
8- use super :: error:: { ParseExpParamError , ParseOhttpKeysParamError , ParseReceiverPubkeyParamError } ;
98use crate :: hpke:: HpkePublicKey ;
109use crate :: ohttp:: OhttpKeys ;
1110
@@ -131,6 +130,87 @@ fn set_param(url: &mut Url, prefix: &str, param: &str) {
131130 url. set_fragment ( if fragment. is_empty ( ) { None } else { Some ( & fragment) } ) ;
132131}
133132
133+ #[ cfg( feature = "v2" ) ]
134+ #[ derive( Debug ) ]
135+ pub ( crate ) enum ParseOhttpKeysParamError {
136+ MissingOhttpKeys ,
137+ InvalidOhttpKeys ( crate :: ohttp:: ParseOhttpKeysError ) ,
138+ }
139+
140+ #[ cfg( feature = "v2" ) ]
141+ impl std:: fmt:: Display for ParseOhttpKeysParamError {
142+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
143+ use ParseOhttpKeysParamError :: * ;
144+
145+ match & self {
146+ MissingOhttpKeys => write ! ( f, "ohttp keys are missing" ) ,
147+ InvalidOhttpKeys ( o) => write ! ( f, "invalid ohttp keys: {}" , o) ,
148+ }
149+ }
150+ }
151+
152+ #[ cfg( feature = "v2" ) ]
153+ #[ derive( Debug ) ]
154+ pub ( crate ) enum ParseExpParamError {
155+ MissingExp ,
156+ InvalidHrp ( bitcoin:: bech32:: Hrp ) ,
157+ DecodeBech32 ( bitcoin:: bech32:: primitives:: decode:: CheckedHrpstringError ) ,
158+ InvalidExp ( bitcoin:: consensus:: encode:: Error ) ,
159+ }
160+
161+ #[ cfg( feature = "v2" ) ]
162+ impl std:: fmt:: Display for ParseExpParamError {
163+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
164+ use ParseExpParamError :: * ;
165+
166+ match & self {
167+ MissingExp => write ! ( f, "exp is missing" ) ,
168+ InvalidHrp ( h) => write ! ( f, "incorrect hrp for exp: {}" , h) ,
169+ DecodeBech32 ( d) => write ! ( f, "exp is not valid bech32: {}" , d) ,
170+ InvalidExp ( i) => write ! ( f, "exp param does not contain a bitcoin consensus encoded u32: {}" , i) ,
171+ }
172+ }
173+ }
174+
175+ #[ cfg( feature = "v2" ) ]
176+ #[ derive( Debug ) ]
177+ pub ( crate ) enum ParseReceiverPubkeyParamError {
178+ MissingPubkey ,
179+ InvalidHrp ( bitcoin:: bech32:: Hrp ) ,
180+ DecodeBech32 ( bitcoin:: bech32:: primitives:: decode:: CheckedHrpstringError ) ,
181+ InvalidPubkey ( crate :: hpke:: HpkeError ) ,
182+ }
183+
184+ #[ cfg( feature = "v2" ) ]
185+ impl std:: fmt:: Display for ParseReceiverPubkeyParamError {
186+ fn fmt ( & self , f : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
187+ use ParseReceiverPubkeyParamError :: * ;
188+
189+ match & self {
190+ MissingPubkey => write ! ( f, "receiver public key is missing" ) ,
191+ InvalidHrp ( h) => write ! ( f, "incorrect hrp for receiver key: {}" , h) ,
192+ DecodeBech32 ( e) => write ! ( f, "receiver public is not valid base64: {}" , e) ,
193+ InvalidPubkey ( e) =>
194+ write ! ( f, "receiver public key does not represent a valid pubkey: {}" , e) ,
195+ }
196+ }
197+ }
198+
199+ #[ cfg( feature = "v2" ) ]
200+ impl std:: error:: Error for ParseReceiverPubkeyParamError {
201+ fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
202+ use ParseReceiverPubkeyParamError :: * ;
203+
204+ match & self {
205+ MissingPubkey => None ,
206+ InvalidHrp ( _) => None ,
207+ DecodeBech32 ( error) => Some ( error) ,
208+ InvalidPubkey ( error) => Some ( error) ,
209+ }
210+ }
211+ }
212+
213+
134214#[ cfg( test) ]
135215mod tests {
136216 use super :: * ;
0 commit comments