-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(refactor) small refactor to the new DIDExchange AnyXYZ wrappers (#1249)
* remove deserialize from any wrappers Signed-off-by: George Mulhearn <gmulhearn@anonyome.com> * simply any wrappers Signed-off-by: George Mulhearn <gmulhearn@anonyome.com> --------- Signed-off-by: George Mulhearn <gmulhearn@anonyome.com> Co-authored-by: George Mulhearn <gmulhearn@anonyome.com>
- Loading branch information
1 parent
1a52699
commit c9b6597
Showing
6 changed files
with
75 additions
and
164 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
52 changes: 52 additions & 0 deletions
52
aries/messages/src/msg_fields/protocols/did_exchange/v1_x/mod.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,7 +1,59 @@ | ||
//! Common components for V1.X DIDExchange messages (v1.0 & v1.1). | ||
//! Necessary to prevent duplicated code, since most types between v1.0 & v1.1 are identical | ||
|
||
use serde::Serialize; | ||
|
||
use super::{v1_0::DidExchangeV1_0, v1_1::DidExchangeV1_1, DidExchange}; | ||
use crate::{msg_types::protocols::did_exchange::DidExchangeTypeV1, AriesMessage}; | ||
|
||
pub mod complete; | ||
pub mod problem_report; | ||
pub mod request; | ||
pub mod response; | ||
|
||
#[derive(Debug, Clone, Serialize, PartialEq)] | ||
#[serde(untagged)] | ||
pub enum DidExchangeV1MessageVariant<V1_0, V1_1> { | ||
V1_0(V1_0), | ||
V1_1(V1_1), | ||
} | ||
|
||
impl<A, B> DidExchangeV1MessageVariant<A, B> { | ||
pub fn get_version(&self) -> DidExchangeTypeV1 { | ||
match self { | ||
DidExchangeV1MessageVariant::V1_0(_) => DidExchangeTypeV1::new_v1_0(), | ||
DidExchangeV1MessageVariant::V1_1(_) => DidExchangeTypeV1::new_v1_1(), | ||
} | ||
} | ||
} | ||
|
||
impl<T> DidExchangeV1MessageVariant<T, T> { | ||
pub fn into_inner(self) -> T { | ||
match self { | ||
DidExchangeV1MessageVariant::V1_0(r) | DidExchangeV1MessageVariant::V1_1(r) => r, | ||
} | ||
} | ||
|
||
pub fn inner(&self) -> &T { | ||
match self { | ||
DidExchangeV1MessageVariant::V1_0(r) | DidExchangeV1MessageVariant::V1_1(r) => r, | ||
} | ||
} | ||
} | ||
|
||
impl<A, B> From<DidExchangeV1MessageVariant<A, B>> for AriesMessage | ||
where | ||
A: Into<DidExchangeV1_0>, | ||
B: Into<DidExchangeV1_1>, | ||
{ | ||
fn from(value: DidExchangeV1MessageVariant<A, B>) -> Self { | ||
match value { | ||
DidExchangeV1MessageVariant::V1_0(a) => { | ||
AriesMessage::DidExchange(DidExchange::V1_0(a.into())) | ||
} | ||
DidExchangeV1MessageVariant::V1_1(b) => { | ||
AriesMessage::DidExchange(DidExchange::V1_1(b.into())) | ||
} | ||
} | ||
} | ||
} |
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