Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nanderstabel committed May 7, 2024
1 parent 048f2fb commit 7037b47
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion oid4vc-core/src/subject_syntax_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,19 @@ impl FromStr for DidMethod {
type Err = serde_json::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut did_scheme = s.splitn(3, ':');
let mut did_scheme = s.splitn(4, ':');

match (
did_scheme.next(),
did_scheme.next(),
did_scheme.next(),
did_scheme.next(),
) {
// (Some("did"), Some(method), Some(submethod), _)
// if !method.is_empty() && !submethod.is_empty() && method.chars().all(char::is_alphanumeric) =>
// {
// Ok(DidMethod(format!("{}:{}", method, submethod)))
// }
(Some("did"), Some(method), _, None) if !method.is_empty() && method.chars().all(char::is_alphanumeric) => {
Ok(DidMethod(method.to_owned()))
}
Expand All @@ -106,6 +111,11 @@ impl Display for DidMethod {
mod tests {
use super::*;

#[test]
fn test() {
assert!(DidMethod::from_str("did:example:123").is_err());
}

#[test]
fn test_did_method() {
assert!(DidMethod::from_str("").is_err());
Expand All @@ -114,6 +124,18 @@ mod tests {
assert!(DidMethod::from_str("invalid:").is_err());
assert!(DidMethod::from_str("did:example_").is_err());
assert!(DidMethod::from_str("did:example").is_ok());
assert!(DidMethod::from_str("did:example:submethod").is_ok());
// assert!(DidMethod::from_str("did:example:submethod:0x123").is_ok());

assert_eq!(DidMethod::from_str("did:example").unwrap().to_string(), "did:example");
assert_eq!(
DidMethod::from_str("did:example:submethod").unwrap().to_string(),
"did:example:submethod"
);
assert_eq!(
DidMethod::from_str("did:example:submethod:0x123").unwrap().to_string(),
"did:example:submethod"
);
}

#[test]
Expand Down

0 comments on commit 7037b47

Please sign in to comment.