@@ -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) =>
171+ write ! ( f, "exp param does not contain a bitcoin consensus encoded u32: {}" , i) ,
172+ }
173+ }
174+ }
175+
176+ #[ cfg( feature = "v2" ) ]
177+ #[ derive( Debug ) ]
178+ pub ( crate ) enum ParseReceiverPubkeyParamError {
179+ MissingPubkey ,
180+ InvalidHrp ( bitcoin:: bech32:: Hrp ) ,
181+ DecodeBech32 ( bitcoin:: bech32:: primitives:: decode:: CheckedHrpstringError ) ,
182+ InvalidPubkey ( crate :: hpke:: HpkeError ) ,
183+ }
184+
185+ #[ cfg( feature = "v2" ) ]
186+ impl std:: fmt:: Display for ParseReceiverPubkeyParamError {
187+ fn fmt ( & self , f : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
188+ use ParseReceiverPubkeyParamError :: * ;
189+
190+ match & self {
191+ MissingPubkey => write ! ( f, "receiver public key is missing" ) ,
192+ InvalidHrp ( h) => write ! ( f, "incorrect hrp for receiver key: {}" , h) ,
193+ DecodeBech32 ( e) => write ! ( f, "receiver public is not valid base64: {}" , e) ,
194+ InvalidPubkey ( e) =>
195+ write ! ( f, "receiver public key does not represent a valid pubkey: {}" , e) ,
196+ }
197+ }
198+ }
199+
200+ #[ cfg( feature = "v2" ) ]
201+ impl std:: error:: Error for ParseReceiverPubkeyParamError {
202+ fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
203+ use ParseReceiverPubkeyParamError :: * ;
204+
205+ match & self {
206+ MissingPubkey => None ,
207+ InvalidHrp ( _) => None ,
208+ DecodeBech32 ( error) => Some ( error) ,
209+ InvalidPubkey ( error) => Some ( error) ,
210+ }
211+ }
212+ }
213+
134214#[ cfg( test) ]
135215mod tests {
136216 use super :: * ;
0 commit comments