diff --git a/aries_vcx/src/handlers/util.rs b/aries_vcx/src/handlers/util.rs index a31af6808a..592017ea65 100644 --- a/aries_vcx/src/handlers/util.rs +++ b/aries_vcx/src/handlers/util.rs @@ -5,6 +5,7 @@ use messages::{ discover_features::DiscoverFeatures, notification::Notification, out_of_band::{invitation::Invitation as OobInvitation, OutOfBand}, + pickup::Pickup, present_proof::{ propose::{Predicate, PresentationAttr}, PresentProof, @@ -180,6 +181,19 @@ pub fn verify_thread_id(thread_id: &str, message: &AriesMessage) -> VcxResult<() AriesMessage::Routing(msg) => msg.id == thread_id, AriesMessage::TrustPing(TrustPing::Ping(msg)) => matches_opt_thread_id!(msg, thread_id), AriesMessage::TrustPing(TrustPing::PingResponse(msg)) => matches_thread_id!(msg, thread_id), + AriesMessage::Pickup(Pickup::Status(msg)) => matches_opt_thread_id!(msg, thread_id), + AriesMessage::Pickup(Pickup::StatusRequest(msg)) => matches_opt_thread_id!(msg, thread_id), + AriesMessage::Pickup(Pickup::Delivery(msg)) => matches_opt_thread_id!(msg, thread_id), + AriesMessage::Pickup(Pickup::DeliveryRequest(msg)) => { + matches_opt_thread_id!(msg, thread_id) + } + + AriesMessage::Pickup(Pickup::MessagesReceived(msg)) => { + matches_opt_thread_id!(msg, thread_id) + } + AriesMessage::Pickup(Pickup::LiveDeliveryChange(msg)) => { + matches_opt_thread_id!(msg, thread_id) + } }; if !is_match { diff --git a/messages/src/decorators/mod.rs b/messages/src/decorators/mod.rs index 3509c41229..6302a2517f 100644 --- a/messages/src/decorators/mod.rs +++ b/messages/src/decorators/mod.rs @@ -3,3 +3,4 @@ pub mod localization; pub mod please_ack; pub mod thread; pub mod timing; +pub mod transport; diff --git a/messages/src/decorators/transport.rs b/messages/src/decorators/transport.rs new file mode 100644 index 0000000000..5ec2e6ac15 --- /dev/null +++ b/messages/src/decorators/transport.rs @@ -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, +} + +#[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("".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": "" } + }); + test_utils::test_serde(transport, expected); + } +} diff --git a/messages/src/lib.rs b/messages/src/lib.rs index 6ac2d5d9f9..eb4f80e93e 100644 --- a/messages/src/lib.rs +++ b/messages/src/lib.rs @@ -15,8 +15,9 @@ pub mod msg_types; use derive_more::From; use misc::utils; -use msg_fields::protocols::cred_issuance::{ - v1::CredentialIssuanceV1, v2::CredentialIssuanceV2, CredentialIssuance, +use msg_fields::protocols::{ + cred_issuance::{v1::CredentialIssuanceV1, v2::CredentialIssuanceV2, CredentialIssuance}, + pickup::Pickup, }; use msg_types::{ cred_issuance::CredentialIssuanceType, report_problem::ReportProblemTypeV1_0, @@ -65,6 +66,7 @@ pub enum AriesMessage { BasicMessage(BasicMessage), OutOfBand(OutOfBand), Notification(Notification), + Pickup(Pickup), } impl DelayedSerde for AriesMessage { @@ -164,6 +166,9 @@ impl DelayedSerde for AriesMessage { Notification::delayed_deserialize((msg_type, kind_str), deserializer) .map(From::from) } + Protocol::PickupType(msg_type) => { + Pickup::delayed_deserialize((msg_type, kind_str), deserializer).map(From::from) + } } } @@ -184,6 +189,7 @@ impl DelayedSerde for AriesMessage { Self::BasicMessage(v) => MsgWithType::from(v).serialize(serializer), Self::OutOfBand(v) => v.delayed_serialize(serializer), Self::Notification(v) => v.delayed_serialize(serializer), + Self::Pickup(v) => v.delayed_serialize(serializer), } } } diff --git a/messages/src/msg_fields/protocols/mod.rs b/messages/src/msg_fields/protocols/mod.rs index c7d73091cc..bae4e6a82c 100644 --- a/messages/src/msg_fields/protocols/mod.rs +++ b/messages/src/msg_fields/protocols/mod.rs @@ -4,6 +4,7 @@ pub mod cred_issuance; pub mod discover_features; pub mod notification; pub mod out_of_band; +pub mod pickup; pub mod present_proof; pub mod report_problem; pub mod revocation; diff --git a/messages/src/msg_fields/protocols/pickup/delivery.rs b/messages/src/msg_fields/protocols/pickup/delivery.rs new file mode 100644 index 0000000000..6e8726a650 --- /dev/null +++ b/messages/src/msg_fields/protocols/pickup/delivery.rs @@ -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; + +#[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, + #[serde(rename = "~attach")] + pub attach: Vec, +} + +#[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, + #[builder(default, setter(strip_option))] + #[serde(rename = "~thread")] + #[serde(skip_serializing_if = "Option::is_none")] + pub thread: Option, +} + +#[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": "" + }, + "@type": "https://didcomm.org/messagepickup/2.0/delivery", + "recipient_key": "", + "~attach": [{ + "@id": "", + "data": { + "base64": "" + } + }] + } + ); + let attach = Attachment::builder() + .id("".to_owned()) + .data( + AttachmentData::builder() + .content(AttachmentType::Base64("".into())) + .build(), + ) + .build(); + let content = DeliveryContent::builder() + .recipient_key("".to_owned()) + .attach(vec![attach]) + .build(); + let decorators = DeliveryDecorators::builder() + .thread( + Thread::builder() + .thid("".to_owned()) + .build(), + ) + .build(); + + test_utils::test_msg(content, decorators, PickupTypeV2_0::Delivery, expected); + } +} diff --git a/messages/src/msg_fields/protocols/pickup/delivery_request.rs b/messages/src/msg_fields/protocols/pickup/delivery_request.rs new file mode 100644 index 0000000000..17d2734b41 --- /dev/null +++ b/messages/src/msg_fields/protocols/pickup/delivery_request.rs @@ -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; + +#[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, +} + +#[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, + #[builder(default, setter(strip_option))] + #[serde(rename = "~transport")] + #[serde(skip_serializing_if = "Option::is_none")] + pub transport: Option, +} + +#[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": "" + } + ); + let content = DeliveryRequestContent::builder() + .recipient_key("".to_owned()) + .limit(10) + .build(); + let decorators = DeliveryRequestDecorators::builder().build(); + + test_utils::test_msg( + content, + decorators, + PickupTypeV2_0::DeliveryRequest, + expected, + ); + } +} diff --git a/messages/src/msg_fields/protocols/pickup/live_delivery_change.rs b/messages/src/msg_fields/protocols/pickup/live_delivery_change.rs new file mode 100644 index 0000000000..ddc6deb752 --- /dev/null +++ b/messages/src/msg_fields/protocols/pickup/live_delivery_change.rs @@ -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; + +#[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, + #[builder(default, setter(strip_option))] + #[serde(rename = "~thread")] + #[serde(skip_serializing_if = "Option::is_none")] + pub thread: Option, +} + +#[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, + ); + } +} diff --git a/messages/src/msg_fields/protocols/pickup/messages_received.rs b/messages/src/msg_fields/protocols/pickup/messages_received.rs new file mode 100644 index 0000000000..47ebdf2151 --- /dev/null +++ b/messages/src/msg_fields/protocols/pickup/messages_received.rs @@ -0,0 +1,57 @@ +use serde::{Deserialize, Serialize}; +use typed_builder::TypedBuilder; + +use crate::{ + decorators::{thread::Thread, transport::Transport}, + msg_parts::MsgParts, +}; + +pub type MessagesReceived = MsgParts; + +#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] +pub struct MessagesReceivedContent { + pub message_id_list: Vec, +} + +#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] +pub struct MessagesReceivedDecorators { + #[builder(default, setter(strip_option))] + #[serde(rename = "~transport")] + #[serde(skip_serializing_if = "Option::is_none")] + pub transport: Option, + #[builder(default, setter(strip_option))] + #[serde(rename = "~thread")] + #[serde(skip_serializing_if = "Option::is_none")] + pub thread: Option, +} + +#[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_messages_received() { + let expected = json!( + { + "@type": "https://didcomm.org/messagepickup/2.0/messages-received", + "message_id_list": ["123","456"] + } + + ); + let content = MessagesReceivedContent::builder() + .message_id_list(vec!["123".to_string(), "456".to_string()]) + .build(); + let decorators = MessagesReceivedDecorators::builder().build(); + + test_utils::test_msg( + content, + decorators, + PickupTypeV2_0::MessagesReceived, + expected, + ); + } +} diff --git a/messages/src/msg_fields/protocols/pickup/mod.rs b/messages/src/msg_fields/protocols/pickup/mod.rs new file mode 100644 index 0000000000..cdc4ec2373 --- /dev/null +++ b/messages/src/msg_fields/protocols/pickup/mod.rs @@ -0,0 +1,100 @@ +mod delivery; +mod delivery_request; +mod live_delivery_change; +mod messages_received; +mod status; +mod status_request; +use derive_more::From; +use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; + +use self::{ + delivery::{Delivery, DeliveryContent, DeliveryDecorators}, + delivery_request::{DeliveryRequest, DeliveryRequestContent, DeliveryRequestDecorators}, + live_delivery_change::{ + LiveDeliveryChange, LiveDeliveryChangeContent, LiveDeliveryChangeDecorators, + }, + messages_received::{MessagesReceived, MessagesReceivedContent, MessagesReceivedDecorators}, + status::{Status, StatusContent, StatusDecorators}, + status_request::{StatusRequest, StatusRequestContent, StatusRequestDecorators}, +}; +use crate::{ + misc::utils::{into_msg_with_type, transit_to_aries_msg}, + msg_fields::traits::DelayedSerde, + msg_types::{ + protocols::pickup::{PickupType, PickupTypeV2, PickupTypeV2_0}, + MsgWithType, + }, +}; + +#[derive(Clone, Debug, From, PartialEq)] +pub enum Pickup { + Status(Status), + StatusRequest(StatusRequest), + DeliveryRequest(DeliveryRequest), + Delivery(Delivery), + MessagesReceived(MessagesReceived), + LiveDeliveryChange(LiveDeliveryChange), +} + +impl DelayedSerde for Pickup { + type MsgType<'a> = (PickupType, &'a str); + + fn delayed_deserialize<'de, D>( + msg_type: Self::MsgType<'de>, + deserializer: D, + ) -> Result + where + D: Deserializer<'de>, + { + let (protocol, kind_str) = msg_type; + + let kind = match protocol { + PickupType::V2(PickupTypeV2::V2_0(kind)) => kind.kind_from_str(kind_str), + }; + + match kind.map_err(D::Error::custom)? { + PickupTypeV2_0::StatusRequest => { + StatusRequest::deserialize(deserializer).map(From::from) + } + PickupTypeV2_0::Status => Status::deserialize(deserializer).map(From::from), + PickupTypeV2_0::DeliveryRequest => { + DeliveryRequest::deserialize(deserializer).map(From::from) + } + PickupTypeV2_0::Delivery => Delivery::deserialize(deserializer).map(From::from), + PickupTypeV2_0::MessagesReceived => { + MessagesReceived::deserialize(deserializer).map(From::from) + } + PickupTypeV2_0::LiveDeliveryChange => { + LiveDeliveryChange::deserialize(deserializer).map(From::from) + } + } + } + + fn delayed_serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::Status(v) => MsgWithType::from(v).serialize(serializer), + Self::StatusRequest(v) => MsgWithType::from(v).serialize(serializer), + Self::Delivery(v) => MsgWithType::from(v).serialize(serializer), + Self::DeliveryRequest(v) => MsgWithType::from(v).serialize(serializer), + Self::MessagesReceived(v) => MsgWithType::from(v).serialize(serializer), + Self::LiveDeliveryChange(v) => MsgWithType::from(v).serialize(serializer), + } + } +} + +transit_to_aries_msg!(StatusContent: StatusDecorators, Pickup); +transit_to_aries_msg!(StatusRequestContent: StatusRequestDecorators, Pickup); +transit_to_aries_msg!(DeliveryContent: DeliveryDecorators, Pickup); +transit_to_aries_msg!(DeliveryRequestContent: DeliveryRequestDecorators, Pickup); +transit_to_aries_msg!(MessagesReceivedContent: MessagesReceivedDecorators, Pickup); +transit_to_aries_msg!(LiveDeliveryChangeContent: LiveDeliveryChangeDecorators, Pickup); + +into_msg_with_type!(Status, PickupTypeV2_0, Status); +into_msg_with_type!(StatusRequest, PickupTypeV2_0, StatusRequest); +into_msg_with_type!(Delivery, PickupTypeV2_0, Delivery); +into_msg_with_type!(DeliveryRequest, PickupTypeV2_0, DeliveryRequest); +into_msg_with_type!(MessagesReceived, PickupTypeV2_0, MessagesReceived); +into_msg_with_type!(LiveDeliveryChange, PickupTypeV2_0, LiveDeliveryChange); diff --git a/messages/src/msg_fields/protocols/pickup/status.rs b/messages/src/msg_fields/protocols/pickup/status.rs new file mode 100644 index 0000000000..0543911844 --- /dev/null +++ b/messages/src/msg_fields/protocols/pickup/status.rs @@ -0,0 +1,58 @@ +use serde::{Deserialize, Serialize}; +use typed_builder::TypedBuilder; + +use crate::{ + decorators::{thread::Thread, transport::Transport}, + msg_parts::MsgParts, +}; + +pub type Status = MsgParts; + +#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] +pub struct StatusContent { + pub message_count: u32, + #[builder(default, setter(strip_option))] + #[serde(skip_serializing_if = "Option::is_none")] + pub recipient_key: Option, +} + +#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] +pub struct StatusDecorators { + #[builder(default, setter(strip_option))] + #[serde(rename = "~transport")] + #[serde(skip_serializing_if = "Option::is_none")] + pub transport: Option, + #[builder(default, setter(strip_option))] + #[serde(rename = "~thread")] + #[serde(skip_serializing_if = "Option::is_none")] + pub thread: Option, +} + +#[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_status() { + let expected = json!( + { + "@id": "123456781", + "@type": "https://didcomm.org/messagepickup/2.0/status", + "recipient_key": "", + "message_count": 7, + } + ); + let content = StatusContent::builder() + .recipient_key("".to_owned()) + .message_count(7) + .build(); + let decorators = StatusDecorators::builder().build(); + + test_utils::test_msg(content, decorators, PickupTypeV2_0::Status, expected); + } +} diff --git a/messages/src/msg_fields/protocols/pickup/status_request.rs b/messages/src/msg_fields/protocols/pickup/status_request.rs new file mode 100644 index 0000000000..cb61f63d89 --- /dev/null +++ b/messages/src/msg_fields/protocols/pickup/status_request.rs @@ -0,0 +1,55 @@ +use serde::{Deserialize, Serialize}; +use typed_builder::TypedBuilder; + +use crate::{ + decorators::{thread::Thread, transport::Transport}, + msg_parts::MsgParts, +}; + +pub type StatusRequest = MsgParts; + +#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] +pub struct StatusRequestContent { + #[builder(default, setter(strip_option))] + #[serde(skip_serializing_if = "Option::is_none")] + pub recipient_key: Option, +} + +#[derive(Clone, Debug, Deserialize, Serialize, Default, PartialEq, TypedBuilder)] +pub struct StatusRequestDecorators { + #[builder(default, setter(strip_option))] + #[serde(rename = "~transport")] + #[serde(skip_serializing_if = "Option::is_none")] + pub transport: Option, + #[builder(default, setter(strip_option))] + #[serde(rename = "~thread")] + #[serde(skip_serializing_if = "Option::is_none")] + pub thread: Option, +} + +#[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_status_request() { + let expected = json!( + { + "@id": "123456781", + "@type": "https://didcomm.org/messagepickup/2.0/status-request", + "recipient_key": "" + } + ); + let content = StatusRequestContent::builder() + .recipient_key("".to_owned()) + .build(); + let decorators = StatusRequestDecorators::builder().build(); + + test_utils::test_msg(content, decorators, PickupTypeV2_0::StatusRequest, expected); + } +} diff --git a/messages/src/msg_types/protocols/mod.rs b/messages/src/msg_types/protocols/mod.rs index 73cb74d936..81060fed83 100644 --- a/messages/src/msg_types/protocols/mod.rs +++ b/messages/src/msg_types/protocols/mod.rs @@ -7,9 +7,9 @@ use shared_vcx::misc::utils::CowStr; use self::{ basic_message::BasicMessageType, connection::ConnectionType, cred_issuance::CredentialIssuanceType, discover_features::DiscoverFeaturesType, - notification::NotificationType, out_of_band::OutOfBandType, present_proof::PresentProofType, - report_problem::ReportProblemType, revocation::RevocationType, routing::RoutingType, - signature::SignatureType, trust_ping::TrustPingType, + notification::NotificationType, out_of_band::OutOfBandType, pickup::PickupType, + present_proof::PresentProofType, report_problem::ReportProblemType, revocation::RevocationType, + routing::RoutingType, signature::SignatureType, trust_ping::TrustPingType, }; use crate::{ error::{MsgTypeError, MsgTypeResult}, @@ -22,6 +22,7 @@ pub mod cred_issuance; pub mod discover_features; pub mod notification; pub mod out_of_band; +pub mod pickup; pub mod present_proof; pub mod report_problem; pub mod revocation; @@ -58,6 +59,7 @@ pub enum Protocol { BasicMessageType(BasicMessageType), OutOfBandType(OutOfBandType), NotificationType(NotificationType), + PickupType(PickupType), } /// Utility macro to avoid harder to read and error prone calling @@ -93,6 +95,7 @@ impl Protocol { match_protocol!(BasicMessageType, protocol, major, minor); match_protocol!(OutOfBandType, protocol, major, minor); match_protocol!(NotificationType, protocol, major, minor); + match_protocol!(PickupType, protocol, major, minor); Err(MsgTypeError::unknown_protocol(protocol.to_owned())) } @@ -112,6 +115,7 @@ impl Protocol { Self::BasicMessageType(v) => v.as_protocol_parts(), Self::OutOfBandType(v) => v.as_protocol_parts(), Self::NotificationType(v) => v.as_protocol_parts(), + Self::PickupType(v) => v.as_protocol_parts(), } } diff --git a/messages/src/msg_types/protocols/pickup.rs b/messages/src/msg_types/protocols/pickup.rs new file mode 100644 index 0000000000..90eb93fe89 --- /dev/null +++ b/messages/src/msg_types/protocols/pickup.rs @@ -0,0 +1,32 @@ +use derive_more::{From, TryInto}; +use messages_macros::MessageType; +use strum_macros::{AsRefStr, EnumString}; +use transitive::Transitive; + +use super::Protocol; +use crate::msg_types::{MsgKindType, Role}; + +#[derive(Copy, Clone, Debug, From, TryInto, PartialEq, MessageType)] +#[msg_type(protocol = "messagepickup")] +pub enum PickupType { + V2(PickupTypeV2), +} + +#[derive(Copy, Clone, Debug, From, TryInto, PartialEq, Transitive, MessageType)] +#[transitive(into(PickupType, Protocol))] +#[msg_type(major = 2)] +pub enum PickupTypeV2 { + #[msg_type(minor = 0, roles = "Role::Mediator")] + V2_0(MsgKindType), +} + +#[derive(Copy, Clone, Debug, AsRefStr, EnumString, PartialEq)] +#[strum(serialize_all = "kebab-case")] +pub enum PickupTypeV2_0 { + Status, + StatusRequest, + DeliveryRequest, + Delivery, + MessagesReceived, + LiveDeliveryChange, +} diff --git a/messages/src/msg_types/registry.rs b/messages/src/msg_types/registry.rs index d387f66d84..f77dc34b3e 100644 --- a/messages/src/msg_types/registry.rs +++ b/messages/src/msg_types/registry.rs @@ -11,6 +11,7 @@ use crate::msg_types::protocols::{ discover_features::DiscoverFeaturesTypeV1, notification::NotificationTypeV1, out_of_band::OutOfBandTypeV1, + pickup::PickupTypeV2, present_proof::PresentProofTypeV1, report_problem::ReportProblemTypeV1, revocation::RevocationTypeV2, @@ -87,6 +88,8 @@ lazy_static! { map_insert(&mut m, extract_parts!(ReportProblemTypeV1::new_v1_0())); map_insert(&mut m, extract_parts!(RevocationTypeV2::new_v2_0())); map_insert(&mut m, extract_parts!(TrustPingTypeV1::new_v1_0())); + map_insert(&mut m, extract_parts!(PickupTypeV2::new_v2_0())); + m }; }