Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions payjoin-ffi/src/receive/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,6 @@ impl From<ProtocolError> for JsonReply {
#[error(transparent)]
pub struct SessionError(#[from] receive::v2::SessionError);

#[uniffi::export]
impl SessionError {
/// Returns `true` if the session has expired.
pub fn is_expired(&self) -> bool { self.0.is_expired() }
}

/// Protocol error raised during output substitution.
#[derive(Debug, thiserror::Error, uniffi::Object)]
#[uniffi::export(Debug, Display)]
Expand Down Expand Up @@ -286,7 +280,6 @@ mod tests {
#[test]
fn session_and_replay_errors_expose_is_expired() {
// uniffi Objects expose the core predicate to bindings.
let _: fn(&SessionError) -> bool = SessionError::is_expired;
let _: fn(&ReceiverReplayError) -> bool = ReceiverReplayError::is_expired;
}

Expand Down
2 changes: 1 addition & 1 deletion payjoin-ffi/src/receive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ impl HasReplyableError {
pub fn create_error_request(
&self,
ohttp_relay: String,
) -> Result<RequestResponse, SessionError> {
) -> Result<RequestResponse, ReceiverCreateRequestError> {
self.0.clone().create_error_request(ohttp_relay).map_err(Into::into).map(|(req, ctx)| {
RequestResponse { request: req.into(), client_response: Arc::new(ctx.into()) }
})
Expand Down
22 changes: 0 additions & 22 deletions payjoin/src/core/receive/v2/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ impl From<InternalSessionError> for SessionError {
fn from(value: InternalSessionError) -> Self { SessionError(value) }
}

impl SessionError {
/// Returns `true` if the session has expired.
pub fn is_expired(&self) -> bool { matches!(self.0, InternalSessionError::Expired(_)) }
}

impl From<crate::into_url::Error> for SessionError {
fn from(e: crate::into_url::Error) -> Self { SessionError(InternalSessionError::ParseUrl(e)) }
}
Expand All @@ -29,10 +24,6 @@ impl From<crate::into_url::Error> for SessionError {
pub(crate) enum InternalSessionError {
/// Url parsing failed
ParseUrl(crate::into_url::Error),
/// The session has expired
Expired(Time),
/// OHTTP Encapsulation failed
OhttpEncapsulation(OhttpEncapsulationError),
/// Hybrid Public Key Encryption failed
Hpke(HpkeError),
/// The directory returned a bad response
Expand All @@ -45,8 +36,6 @@ impl fmt::Display for SessionError {

match &self.0 {
ParseUrl(e) => write!(f, "URL parsing failed: {e}"),
Expired(expiration) => write!(f, "Session expired at {expiration:?}"),
OhttpEncapsulation(e) => write!(f, "OHTTP Encapsulation Error: {e}"),
Hpke(e) => write!(f, "Hpke decryption failed: {e}"),
DirectoryResponse(e) => write!(f, "Directory response error: {e}"),
}
Expand All @@ -59,8 +48,6 @@ impl error::Error for SessionError {

match &self.0 {
ParseUrl(e) => Some(e),
Expired(_) => None,
OhttpEncapsulation(e) => Some(e),
Hpke(e) => Some(e),
DirectoryResponse(e) => Some(e),
}
Expand Down Expand Up @@ -144,15 +131,6 @@ impl From<OhttpEncapsulationError> for CreateRequestError {
mod tests {
use super::*;

#[test]
fn session_error_is_expired() {
let expired = SessionError(InternalSessionError::Expired(Time::now()));
assert!(expired.is_expired());

let other = SessionError(InternalSessionError::ParseUrl(crate::into_url::Error::BadScheme));
assert!(!other.is_expired());
}

#[test]
fn create_request_error_is_expired() {
let expired = CreateRequestError(InternalCreateRequestError::Expired(Time::now()));
Expand Down
11 changes: 5 additions & 6 deletions payjoin/src/core/receive/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1397,10 +1397,10 @@ impl Receiver<HasReplyableError> {
pub fn create_error_request(
&self,
ohttp_relay: impl IntoUrl,
) -> Result<(Request, OhttpResponse), SessionError> {
) -> Result<(Request, OhttpResponse), CreateRequestError> {
let session_context = &self.session_context;
if session_context.expiration.elapsed() {
return Err(InternalSessionError::Expired(session_context.expiration).into());
return Err(InternalCreateRequestError::Expired(self.session_context.expiration).into());
}
let mailbox =
mailbox_endpoint(&session_context.directory, &session_context.reply_mailbox_id());
Expand All @@ -1410,8 +1410,7 @@ impl Receiver<HasReplyableError> {
self.error_reply.to_json().to_string().into_bytes(),
&session_context.receiver_key,
reply_key,
)
.map_err(InternalSessionError::Hpke)?
)?
} else {
// Post a generic unavailable error message in the case where we don't have a reply key
let err =
Expand All @@ -1421,7 +1420,7 @@ impl Receiver<HasReplyableError> {
};
let (body, ohttp_ctx) =
ohttp_encapsulate(&session_context.ohttp_keys, "POST", mailbox.as_str(), Some(&body))
.map_err(InternalSessionError::OhttpEncapsulation)?;
.map_err(InternalCreateRequestError::OhttpEncapsulation)?;
let req = Request::new_v2(&session_context.full_relay_url(ohttp_relay)?, &body);
Ok((req, OhttpResponse::new(ohttp_ctx)))
}
Expand Down Expand Up @@ -1995,7 +1994,7 @@ pub mod test {
match expiration {
Err(error) => assert_eq!(
error.to_string(),
SessionError::from(InternalSessionError::Expired(now)).to_string()
CreateRequestError::from(InternalCreateRequestError::Expired(now)).to_string()
),
Ok(_) => panic!("Expected session expiration error, got success"),
}
Expand Down
Loading