Skip to content

Commit c34f620

Browse files
committed
Move url_ext-specific errors to url_ext.rs
1 parent c859e67 commit c34f620

File tree

4 files changed

+83
-83
lines changed

4 files changed

+83
-83
lines changed

payjoin/src/send/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use bitcoin::transaction::Version;
55
use bitcoin::{AddressType, Sequence};
66

77
#[cfg(feature = "v2")]
8-
use crate::uri::error::ParseReceiverPubkeyParamError;
8+
use crate::uri::url_ext::ParseReceiverPubkeyParamError;
99

1010
/// Error that may occur when the response from receiver is malformed.
1111
///

payjoin/src/send/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ impl Sender {
331331
#[cfg(feature = "v2")]
332332
fn extract_rs_pubkey(
333333
&self,
334-
) -> Result<HpkePublicKey, crate::uri::error::ParseReceiverPubkeyParamError> {
334+
) -> Result<HpkePublicKey, crate::uri::url_ext::ParseReceiverPubkeyParamError> {
335335
use crate::uri::UrlExt;
336336
self.endpoint.receiver_pubkey()
337337
}

payjoin/src/uri/error.rs

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -11,86 +11,6 @@ pub(crate) enum InternalPjParseError {
1111
UnsecureEndpoint,
1212
}
1313

14-
#[cfg(feature = "v2")]
15-
#[derive(Debug)]
16-
pub(crate) enum ParseOhttpKeysParamError {
17-
MissingOhttpKeys,
18-
InvalidOhttpKeys(crate::ohttp::ParseOhttpKeysError),
19-
}
20-
21-
#[cfg(feature = "v2")]
22-
#[derive(Debug)]
23-
pub(crate) enum ParseExpParamError {
24-
MissingExp,
25-
InvalidHrp(bitcoin::bech32::Hrp),
26-
DecodeBech32(bitcoin::bech32::primitives::decode::CheckedHrpstringError),
27-
InvalidExp(bitcoin::consensus::encode::Error),
28-
}
29-
30-
#[cfg(feature = "v2")]
31-
impl std::fmt::Display for ParseExpParamError {
32-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33-
use ParseExpParamError::*;
34-
35-
match &self {
36-
MissingExp => write!(f, "exp is missing"),
37-
InvalidHrp(h) => write!(f, "incorrect hrp for exp: {}", h),
38-
DecodeBech32(d) => write!(f, "exp is not valid bech32: {}", d),
39-
InvalidExp(i) => write!(f, "exp param does not contain a bitcoin consensus encoded u32: {}", i),
40-
}
41-
}
42-
}
43-
44-
#[cfg(feature = "v2")]
45-
impl std::fmt::Display for ParseOhttpKeysParamError {
46-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47-
use ParseOhttpKeysParamError::*;
48-
49-
match &self {
50-
MissingOhttpKeys => write!(f, "ohttp keys are missing"),
51-
InvalidOhttpKeys(o) => write!(f, "invalid ohttp keys: {}", o),
52-
}
53-
}
54-
}
55-
56-
#[cfg(feature = "v2")]
57-
#[derive(Debug)]
58-
pub(crate) enum ParseReceiverPubkeyParamError {
59-
MissingPubkey,
60-
InvalidHrp(bitcoin::bech32::Hrp),
61-
DecodeBech32(bitcoin::bech32::primitives::decode::CheckedHrpstringError),
62-
InvalidPubkey(crate::hpke::HpkeError),
63-
}
64-
65-
#[cfg(feature = "v2")]
66-
impl std::fmt::Display for ParseReceiverPubkeyParamError {
67-
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
68-
use ParseReceiverPubkeyParamError::*;
69-
70-
match &self {
71-
MissingPubkey => write!(f, "receiver public key is missing"),
72-
InvalidHrp(h) => write!(f, "incorrect hrp for receiver key: {}", h),
73-
DecodeBech32(e) => write!(f, "receiver public is not valid base64: {}", e),
74-
InvalidPubkey(e) =>
75-
write!(f, "receiver public key does not represent a valid pubkey: {}", e),
76-
}
77-
}
78-
}
79-
80-
#[cfg(feature = "v2")]
81-
impl std::error::Error for ParseReceiverPubkeyParamError {
82-
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
83-
use ParseReceiverPubkeyParamError::*;
84-
85-
match &self {
86-
MissingPubkey => None,
87-
InvalidHrp(_) => None,
88-
DecodeBech32(error) => Some(error),
89-
InvalidPubkey(error) => Some(error),
90-
}
91-
}
92-
}
93-
9414
impl From<InternalPjParseError> for PjParseError {
9515
fn from(value: InternalPjParseError) -> Self { PjParseError(value) }
9616
}

payjoin/src/uri/url_ext.rs

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use bitcoin::consensus::encode::Decodable;
55
use bitcoin::consensus::Encodable;
66
use url::Url;
77

8-
use super::error::{ParseExpParamError, ParseOhttpKeysParamError, ParseReceiverPubkeyParamError};
98
use crate::hpke::HpkePublicKey;
109
use 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)]
135215
mod tests {
136216
use super::*;

0 commit comments

Comments
 (0)