Skip to content

Commit

Permalink
Work around cardinality issues
Browse files Browse the repository at this point in the history
  • Loading branch information
clehner committed Aug 27, 2020
1 parent 2c95d18 commit 33cb0e5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/bin/ssi-vc-test/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use ssi::jwk::JWTKeys;
use ssi::vc::Contexts;
use ssi::vc::Context;
use ssi::vc::Credential;
use ssi::vc::OneOrMany;
use ssi::vc::Presentation;

fn usage() {
Expand Down Expand Up @@ -33,12 +34,14 @@ fn generate(data: String) -> String {
}

// work around https://github.com/w3c/vc-test-suite/issues/96
if doc.type_.len() > 1 {
if let Contexts::Many(ref context) = doc.context {
if context.len() == 1 {
panic!("If there are multiple types, there should be multiple contexts.");
}
}
let contexts: &OneOrMany<Context> = &doc.context.clone().into();
if doc.type_.len() > 1 && contexts.len() <= 1 {
panic!("If there are multiple types, there should be multiple contexts.");
}

// work around https://github.com/w3c/vc-test-suite/issues/97
if contexts.len() > 1 && doc.type_.len() <= 1 {
panic!("If there are multiple contexts, there should be multiple types.");
}

serde_json::to_string_pretty(&doc).unwrap()
Expand Down
9 changes: 9 additions & 0 deletions src/vc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,15 @@ impl TryFrom<OneOrMany<Context>> for Contexts {
}
}

impl From<Contexts> for OneOrMany<Context> {
fn from(contexts: Contexts) -> OneOrMany<Context> {
match contexts {
Contexts::One(context) => OneOrMany::One(context),
Contexts::Many(contexts) => OneOrMany::Many(contexts),
}
}
}

impl TryFrom<String> for URI {
type Error = Error;
fn try_from(uri: String) -> Result<Self, Self::Error> {
Expand Down

0 comments on commit 33cb0e5

Please sign in to comment.