-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into 40-implement-a-secure…
…-key-storage-functionality-for-the-pop-server
- Loading branch information
Showing
26 changed files
with
533 additions
and
555 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 20 additions & 16 deletions
36
crates/web-plugins/didcomm-messaging/protocols/forward/src/error.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
use axum::Json; | ||
use serde_json::{json, Value}; | ||
use axum::{response::IntoResponse, Json}; | ||
use hyper::StatusCode; | ||
use thiserror::Error; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum RoutingError { | ||
pub enum ForwardError { | ||
#[error("message body is malformed")] | ||
MalformedBody, | ||
#[error("Repository not set")] | ||
RepostitoryError | ||
} | ||
impl RoutingError { | ||
/// Converts the error to an axum JSON representation. | ||
pub fn json(&self) -> Json<Value> { | ||
Json(json!({ | ||
"error": self.to_string() | ||
})) | ||
} | ||
#[error("Uncoordinated sender")] | ||
UncoordinatedSender, | ||
#[error("Internal server error")] | ||
InternalServerError, | ||
} | ||
|
||
impl From<RoutingError> for Json<Value> { | ||
fn from(error: RoutingError) -> Self { | ||
error.json() | ||
impl IntoResponse for ForwardError { | ||
fn into_response(self) -> axum::response::Response { | ||
let status_code = match self { | ||
ForwardError::MalformedBody => StatusCode::BAD_REQUEST, | ||
ForwardError::UncoordinatedSender => StatusCode::UNAUTHORIZED, | ||
ForwardError::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR, | ||
}; | ||
|
||
let body = Json(serde_json::json!({ | ||
"error": self.to_string(), | ||
})); | ||
|
||
(status_code, body).into_response() | ||
} | ||
} |
4 changes: 3 additions & 1 deletion
4
crates/web-plugins/didcomm-messaging/protocols/forward/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
mod error; | ||
|
||
pub mod web; | ||
|
||
// Re-exports | ||
pub use error::ForwardError; |
10 changes: 5 additions & 5 deletions
10
crates/web-plugins/didcomm-messaging/protocols/forward/src/web/handler.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
use super::routing::handler; | ||
use axum::response::Response; | ||
use crate::{web::routing::handler, ForwardError}; | ||
use didcomm::Message; | ||
use shared::state::AppState; | ||
use std::sync::Arc; | ||
|
||
/// Mediator receives forwarded messages, extract the next field in the message body, and the attachments in the message | ||
/// then stores the attachment with the next field as key for pickup | ||
pub async fn mediator_forward_process( | ||
state: &AppState, | ||
state: Arc<AppState>, | ||
payload: Message, | ||
) -> Result<Message, Response> { | ||
let result = handler(state, payload).await.unwrap(); | ||
) -> Result<Option<Message>, ForwardError> { | ||
let result = handler(state.clone(), payload).await.unwrap(); | ||
Ok(result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
crates/web-plugins/didcomm-messaging/protocols/mediator-coordination/src/errors.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use axum::{response::IntoResponse, Json}; | ||
use hyper::StatusCode; | ||
use thiserror::Error; | ||
|
||
/// Represents errors that can occur during mediation. | ||
#[derive(Debug, Error, PartialEq, Eq)] | ||
pub enum MediationError { | ||
#[error("No return route all decoration")] | ||
NoReturnRouteAllDecoration, | ||
#[error("invalid message type")] | ||
InvalidMessageType, | ||
#[error("uncoordinated sender")] | ||
UncoordinatedSender, | ||
#[error("could not parse into expected message format")] | ||
UnexpectedMessageFormat, | ||
} | ||
|
||
impl IntoResponse for MediationError { | ||
fn into_response(self) -> axum::response::Response { | ||
let status_code = match self { | ||
MediationError::NoReturnRouteAllDecoration | MediationError::InvalidMessageType => { | ||
StatusCode::BAD_REQUEST | ||
} | ||
MediationError::UncoordinatedSender => StatusCode::UNAUTHORIZED, | ||
MediationError::UnexpectedMessageFormat => StatusCode::BAD_REQUEST, | ||
}; | ||
|
||
let body = Json(serde_json::json!({ | ||
"error": self.to_string(), | ||
})); | ||
|
||
(status_code, body).into_response() | ||
} | ||
} |
8 changes: 6 additions & 2 deletions
8
crates/web-plugins/didcomm-messaging/protocols/mediator-coordination/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
mod errors; | ||
mod jose; | ||
mod model; | ||
|
||
pub mod client; | ||
pub mod web; | ||
|
||
mod jose; | ||
mod model; | ||
// Re-exports | ||
pub use errors::MediationError; |
Oops, something went wrong.