forked from hyperledger/aries-vcx
-
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.
Add support for pickup protocol messages (hyperledger#1018)
Add support for mediation related protocol messages (hyperledger#1018) Signed-off-by: Naian <126972030+nain-F49FF806@users.noreply.github.com>
- Loading branch information
1 parent
3f1045c
commit 787b51c
Showing
15 changed files
with
604 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ pub mod localization; | |
pub mod please_ack; | ||
pub mod thread; | ||
pub mod timing; | ||
pub mod transport; |
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,63 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use typed_builder::TypedBuilder; | ||
|
||
use crate::decorators::thread::Thread; | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] | ||
pub struct Transport { | ||
pub return_route: ReturnRoute, | ||
#[builder(default, setter(strip_option))] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub return_route_thread: Option<Thread>, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq)] | ||
pub enum ReturnRoute { | ||
#[default] | ||
#[serde(rename = "none")] | ||
None, | ||
#[serde(rename = "all")] | ||
All, | ||
#[serde(rename = "thread")] | ||
Thread, | ||
} | ||
|
||
#[cfg(test)] | ||
#[allow(clippy::unwrap_used)] | ||
#[allow(clippy::field_reassign_with_default)] | ||
mod tests { | ||
use serde_json::json; | ||
|
||
use super::*; | ||
use crate::misc::test_utils; | ||
|
||
#[test] | ||
fn test_transport_minimals() { | ||
// all variant | ||
let transport = Transport::builder().return_route(ReturnRoute::All).build(); | ||
let expected = json!({ | ||
"return_route": "all" | ||
}); | ||
test_utils::test_serde(transport, expected); | ||
// none variant | ||
let transport = Transport::builder().return_route(ReturnRoute::None).build(); | ||
let expected = json!({ | ||
"return_route": "none" | ||
}); | ||
test_utils::test_serde(transport, expected); | ||
} | ||
#[test] | ||
fn test_transport_extended() { | ||
// thread variant | ||
let thread = Thread::builder().thid("<thread id>".to_string()).build(); | ||
let transport = Transport::builder() | ||
.return_route(ReturnRoute::Thread) | ||
.return_route_thread(thread) | ||
.build(); | ||
let expected = json!({ | ||
"return_route": "thread", | ||
"return_route_thread": { "thid": "<thread id>" } | ||
}); | ||
test_utils::test_serde(transport, expected); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use typed_builder::TypedBuilder; | ||
|
||
use crate::{ | ||
decorators::{attachment::Attachment, thread::Thread, transport::Transport}, | ||
msg_parts::MsgParts, | ||
}; | ||
|
||
pub type Delivery = MsgParts<DeliveryContent, DeliveryDecorators>; | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] | ||
pub struct DeliveryContent { | ||
#[builder(default, setter(strip_option))] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub recipient_key: Option<String>, | ||
#[serde(rename = "~attach")] | ||
pub attach: Vec<Attachment>, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] | ||
pub struct DeliveryDecorators { | ||
#[builder(default, setter(strip_option))] | ||
#[serde(rename = "~transport")] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub transport: Option<Transport>, | ||
#[builder(default, setter(strip_option))] | ||
#[serde(rename = "~thread")] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub thread: Option<Thread>, | ||
} | ||
|
||
#[cfg(test)] | ||
#[allow(clippy::unwrap_used)] | ||
#[allow(clippy::field_reassign_with_default)] | ||
mod tests { | ||
use serde_json::json; | ||
|
||
use super::*; | ||
use crate::{ | ||
decorators::{ | ||
attachment::{AttachmentData, AttachmentType}, | ||
thread::Thread, | ||
}, | ||
misc::test_utils, | ||
msg_types::protocols::pickup::PickupTypeV2_0, | ||
}; | ||
#[test] | ||
fn test_delivery() { | ||
let expected = json!( | ||
{ | ||
"@id": "123456781", | ||
"~thread": { | ||
"thid": "<message id of delivery-request message>" | ||
}, | ||
"@type": "https://didcomm.org/messagepickup/2.0/delivery", | ||
"recipient_key": "<key for messages>", | ||
"~attach": [{ | ||
"@id": "<messageid>", | ||
"data": { | ||
"base64": "" | ||
} | ||
}] | ||
} | ||
); | ||
let attach = Attachment::builder() | ||
.id("<messageid>".to_owned()) | ||
.data( | ||
AttachmentData::builder() | ||
.content(AttachmentType::Base64("".into())) | ||
.build(), | ||
) | ||
.build(); | ||
let content = DeliveryContent::builder() | ||
.recipient_key("<key for messages>".to_owned()) | ||
.attach(vec![attach]) | ||
.build(); | ||
let decorators = DeliveryDecorators::builder() | ||
.thread( | ||
Thread::builder() | ||
.thid("<message id of delivery-request message>".to_owned()) | ||
.build(), | ||
) | ||
.build(); | ||
|
||
test_utils::test_msg(content, decorators, PickupTypeV2_0::Delivery, expected); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
messages/src/msg_fields/protocols/pickup/delivery_request.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,62 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use typed_builder::TypedBuilder; | ||
|
||
use crate::{ | ||
decorators::{thread::Thread, transport::Transport}, | ||
msg_parts::MsgParts, | ||
}; | ||
|
||
pub type DeliveryRequest = MsgParts<DeliveryRequestContent, DeliveryRequestDecorators>; | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] | ||
pub struct DeliveryRequestContent { | ||
pub limit: u32, | ||
#[builder(default, setter(strip_option))] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub recipient_key: Option<String>, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] | ||
pub struct DeliveryRequestDecorators { | ||
#[builder(default, setter(strip_option))] | ||
#[serde(rename = "~thread")] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub thread: Option<Thread>, | ||
#[builder(default, setter(strip_option))] | ||
#[serde(rename = "~transport")] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub transport: Option<Transport>, | ||
} | ||
|
||
#[cfg(test)] | ||
#[allow(clippy::unwrap_used)] | ||
#[allow(clippy::field_reassign_with_default)] | ||
mod tests { | ||
use serde_json::json; | ||
|
||
use super::*; | ||
use crate::{misc::test_utils, msg_types::protocols::pickup::PickupTypeV2_0}; | ||
#[test] | ||
fn test_delivery_request() { | ||
let expected = json!( | ||
{ | ||
"@id": "123456781", | ||
"@type": "https://didcomm.org/messagepickup/2.0/delivery-request", | ||
"limit": 10, | ||
"recipient_key": "<key for messages>" | ||
} | ||
); | ||
let content = DeliveryRequestContent::builder() | ||
.recipient_key("<key for messages>".to_owned()) | ||
.limit(10) | ||
.build(); | ||
let decorators = DeliveryRequestDecorators::builder().build(); | ||
|
||
test_utils::test_msg( | ||
content, | ||
decorators, | ||
PickupTypeV2_0::DeliveryRequest, | ||
expected, | ||
); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
messages/src/msg_fields/protocols/pickup/live_delivery_change.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,56 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use typed_builder::TypedBuilder; | ||
|
||
use crate::{ | ||
decorators::{thread::Thread, transport::Transport}, | ||
msg_parts::MsgParts, | ||
}; | ||
|
||
pub type LiveDeliveryChange = MsgParts<LiveDeliveryChangeContent, LiveDeliveryChangeDecorators>; | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] | ||
pub struct LiveDeliveryChangeContent { | ||
pub live_delivery: bool, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] | ||
pub struct LiveDeliveryChangeDecorators { | ||
#[builder(default, setter(strip_option))] | ||
#[serde(rename = "~transport")] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub transport: Option<Transport>, | ||
#[builder(default, setter(strip_option))] | ||
#[serde(rename = "~thread")] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub thread: Option<Thread>, | ||
} | ||
|
||
#[cfg(test)] | ||
#[allow(clippy::unwrap_used)] | ||
#[allow(clippy::field_reassign_with_default)] | ||
mod tests { | ||
use serde_json::json; | ||
|
||
use super::*; | ||
use crate::{misc::test_utils, msg_types::protocols::pickup::PickupTypeV2_0}; | ||
#[test] | ||
fn test_live_delivery_change() { | ||
let expected = json!( | ||
{ | ||
"@type": "https://didcomm.org/messagepickup/2.0/live-delivery-change", | ||
"live_delivery": true | ||
} | ||
); | ||
let content = LiveDeliveryChangeContent::builder() | ||
.live_delivery(true) | ||
.build(); | ||
let decorators = LiveDeliveryChangeDecorators::builder().build(); | ||
|
||
test_utils::test_msg( | ||
content, | ||
decorators, | ||
PickupTypeV2_0::LiveDeliveryChange, | ||
expected, | ||
); | ||
} | ||
} |
Oops, something went wrong.