Skip to content

Commit

Permalink
fix: fix Deserialize for DidMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
nanderstabel committed May 9, 2024
1 parent 05959ca commit 7fdd207
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions oid4vc-core/src/subject_syntax_type.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::{de::Error, Deserialize, Deserializer, Serialize};
use serde_with::{DeserializeFromStr, SerializeDisplay};
use serde_with::SerializeDisplay;
use std::{fmt::Display, str::FromStr};

#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
Expand Down Expand Up @@ -69,7 +69,7 @@ pub mod serde_unit_variant {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, DeserializeFromStr, SerializeDisplay)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, SerializeDisplay)]
pub struct DidMethod {
method_name: String,
namespace: Option<String>,
Expand Down Expand Up @@ -102,6 +102,18 @@ impl DidMethod {
}
}

impl<'de> Deserialize<'de> for DidMethod {
fn deserialize<D>(deserializer: D) -> Result<DidMethod, D::Error>
where
D: Deserializer<'de>,
{
let s: String = Deserialize::deserialize(deserializer)?;
DidMethod::from_str_with_namespace(&s)
.or_else(|_| DidMethod::from_str(&s))
.map_err(D::Error::custom)
}
}

impl From<did_url::DID> for DidMethod {
fn from(did: did_url::DID) -> Self {
DidMethod {
Expand Down

0 comments on commit 7fdd207

Please sign in to comment.