Removed duplicated code

This commit is contained in:
Xavi Aracil 2022-11-15 10:14:51 +01:00
parent 347f44e804
commit 2a6b045f0c

View File

@ -25,7 +25,7 @@ import jakarta.json.JsonStructure;
/** /**
* A Probe that verifies a credential's embedded proof. * A Probe that verifies a credential's embedded proof.
* *
* @author mgylling * @author mgylling
*/ */
public class EmbeddedProofProbe extends Probe<Credential> { public class EmbeddedProofProbe extends Probe<Credential> {
@ -40,16 +40,14 @@ public class EmbeddedProofProbe extends Probe<Credential> {
*/ */
@Override @Override
public ReportItems run(Credential crd, RunContext ctx) throws Exception { public ReportItems run(Credential crd, RunContext ctx) throws Exception {
// TODO: What there are multiple proofs? // TODO: What there are multiple proofs?
VerifiableCredential vc = VerifiableCredential.fromJson(new StringReader(crd.getJson().toString())); VerifiableCredential vc = VerifiableCredential.fromJson(new StringReader(crd.getJson().toString()));
ConfigurableDocumentLoader documentLoader = new ConfigurableDocumentLoader(); ConfigurableDocumentLoader documentLoader = new ConfigurableDocumentLoader();
documentLoader.setEnableHttp(true); documentLoader.setEnableHttp(true);
documentLoader.setEnableHttps(true); documentLoader.setEnableHttps(true);
vc.setDocumentLoader(new CachingDocumentLoader()); vc.setDocumentLoader(documentLoader);
vc.setDocumentLoader(documentLoader);
URI method = vc.getLdProof().getVerificationMethod();
LdProof proof = vc.getLdProof(); LdProof proof = vc.getLdProof();
if (proof == null) { if (proof == null) {
@ -93,11 +91,11 @@ public class EmbeddedProofProbe extends Probe<Credential> {
} }
} else if (method.getScheme().equals("http") || method.getScheme().equals("https")) { } else if (method.getScheme().equals("http") || method.getScheme().equals("https")) {
// TODO: Can we use proof.getDocumentLoader()? // TODO: Can we use proof.getDocumentLoader()?
ConfigurableDocumentLoader documentLoader = new ConfigurableDocumentLoader(); ConfigurableDocumentLoader keyDocumentLoader = new ConfigurableDocumentLoader();
documentLoader.setEnableHttp(true); keyDocumentLoader.setEnableHttp(true);
documentLoader.setEnableHttps(true); keyDocumentLoader.setEnableHttps(true);
Document keyDocument = documentLoader.loadDocument(method, new DocumentLoaderOptions()); Document keyDocument = keyDocumentLoader.loadDocument(method, new DocumentLoaderOptions());
Optional<JsonStructure> keyStructure = keyDocument.getJsonContent(); Optional<JsonStructure> keyStructure = keyDocument.getJsonContent();
if (keyStructure.isEmpty()) { if (keyStructure.isEmpty()) {
return error("Key document not found at " + method, ctx); return error("Key document not found at " + method, ctx);