Skip to content

Commit accdaca

Browse files
committed
Rename ParseReceiverPubkeyError to ParseReceiverPubkeyParamError
This change will differentiate between parsing a receiver pubkey in the context of a URL and other formats
1 parent 9e60019 commit accdaca

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

payjoin/src/send/error.rs

Lines changed: 4 additions & 4 deletions
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::ParseReceiverPubkeyError;
8+
use crate::uri::error::ParseReceiverPubkeyParamError;
99

1010
/// Error that may occur when the response from receiver is malformed.
1111
///
@@ -203,7 +203,7 @@ pub(crate) enum InternalCreateRequestError {
203203
#[cfg(feature = "v2")]
204204
OhttpEncapsulation(crate::ohttp::OhttpEncapsulationError),
205205
#[cfg(feature = "v2")]
206-
ParseReceiverPubkey(ParseReceiverPubkeyError),
206+
ParseReceiverPubkey(ParseReceiverPubkeyParamError),
207207
#[cfg(feature = "v2")]
208208
MissingOhttpConfig,
209209
#[cfg(feature = "v2")]
@@ -287,8 +287,8 @@ impl From<crate::psbt::AddressTypeError> for CreateRequestError {
287287
}
288288

289289
#[cfg(feature = "v2")]
290-
impl From<ParseReceiverPubkeyError> for CreateRequestError {
291-
fn from(value: ParseReceiverPubkeyError) -> Self {
290+
impl From<ParseReceiverPubkeyParamError> for CreateRequestError {
291+
fn from(value: ParseReceiverPubkeyParamError) -> Self {
292292
CreateRequestError(InternalCreateRequestError::ParseReceiverPubkey(value))
293293
}
294294
}

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::ParseReceiverPubkeyError> {
334+
) -> Result<HpkePublicKey, crate::uri::error::ParseReceiverPubkeyParamError> {
335335
use crate::uri::UrlExt;
336336
self.endpoint.receiver_pubkey()
337337
}

payjoin/src/uri/error.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ impl std::fmt::Display for ParseOhttpKeysParamError {
3232

3333
#[cfg(feature = "v2")]
3434
#[derive(Debug)]
35-
pub(crate) enum ParseReceiverPubkeyError {
35+
pub(crate) enum ParseReceiverPubkeyParamError {
3636
MissingPubkey,
3737
InvalidHrp(bitcoin::bech32::Hrp),
3838
DecodeBech32(bitcoin::bech32::primitives::decode::CheckedHrpstringError),
3939
InvalidPubkey(crate::hpke::HpkeError),
4040
}
4141

4242
#[cfg(feature = "v2")]
43-
impl std::fmt::Display for ParseReceiverPubkeyError {
43+
impl std::fmt::Display for ParseReceiverPubkeyParamError {
4444
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
45-
use ParseReceiverPubkeyError::*;
45+
use ParseReceiverPubkeyParamError::*;
4646

4747
match &self {
4848
MissingPubkey => write!(f, "receiver public key is missing"),
@@ -55,9 +55,9 @@ impl std::fmt::Display for ParseReceiverPubkeyError {
5555
}
5656

5757
#[cfg(feature = "v2")]
58-
impl std::error::Error for ParseReceiverPubkeyError {
58+
impl std::error::Error for ParseReceiverPubkeyParamError {
5959
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
60-
use ParseReceiverPubkeyError::*;
60+
use ParseReceiverPubkeyParamError::*;
6161

6262
match &self {
6363
MissingPubkey => None,

payjoin/src/uri/url_ext.rs

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

8-
use super::error::{ParseOhttpKeysParamError, ParseReceiverPubkeyError};
8+
use super::error::{ParseOhttpKeysParamError, ParseReceiverPubkeyParamError};
99
use crate::hpke::HpkePublicKey;
1010
use crate::ohttp::OhttpKeys;
1111

1212
/// Parse and set fragment parameters from `&pj=` URI parameter URLs
1313
pub(crate) trait UrlExt {
14-
fn receiver_pubkey(&self) -> Result<HpkePublicKey, ParseReceiverPubkeyError>;
14+
fn receiver_pubkey(&self) -> Result<HpkePublicKey, ParseReceiverPubkeyParamError>;
1515
fn set_receiver_pubkey(&mut self, exp: HpkePublicKey);
1616
fn ohttp(&self) -> Result<OhttpKeys, ParseOhttpKeysParamError>;
1717
fn set_ohttp(&mut self, ohttp: OhttpKeys);
@@ -21,20 +21,20 @@ pub(crate) trait UrlExt {
2121

2222
impl UrlExt for Url {
2323
/// Retrieve the receiver's public key from the URL fragment
24-
fn receiver_pubkey(&self) -> Result<HpkePublicKey, ParseReceiverPubkeyError> {
24+
fn receiver_pubkey(&self) -> Result<HpkePublicKey, ParseReceiverPubkeyParamError> {
2525
let value = get_param(self, "RK1", |v| Some(v.to_owned()))
26-
.ok_or(ParseReceiverPubkeyError::MissingPubkey)?;
26+
.ok_or(ParseReceiverPubkeyParamError::MissingPubkey)?;
2727

2828
let (hrp, bytes) = crate::bech32::nochecksum::decode(&value)
29-
.map_err(ParseReceiverPubkeyError::DecodeBech32)?;
29+
.map_err(ParseReceiverPubkeyParamError::DecodeBech32)?;
3030

3131
let rk_hrp: Hrp = Hrp::parse("RK").unwrap();
3232
if hrp != rk_hrp {
33-
return Err(ParseReceiverPubkeyError::InvalidHrp(hrp));
33+
return Err(ParseReceiverPubkeyParamError::InvalidHrp(hrp));
3434
}
3535

3636
HpkePublicKey::from_compressed_bytes(&bytes[..])
37-
.map_err(ParseReceiverPubkeyError::InvalidPubkey)
37+
.map_err(ParseReceiverPubkeyParamError::InvalidPubkey)
3838
}
3939

4040
/// Set the receiver's public key in the URL fragment

0 commit comments

Comments
 (0)