Skip to content

Commit 9106166

Browse files
committed
Add methods for more information about the verification process
1 parent f95b573 commit 9106166

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/main/java/com/danubetech/dataintegrity/verifier/LdVerifier.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static LdVerifier<? extends DataIntegritySuite> ldVerifierForDataIntegrit
4747
return LdVerifierRegistry.getLdVerifierByDataIntegritySuite(dataIntegritySuite);
4848
}
4949

50-
public boolean verify(JsonLDObject jsonLdObject, DataIntegrityProof dataIntegrityProof) throws IOException, GeneralSecurityException, JsonLDException {
50+
public LdVerifierResult verifyWithResult(JsonLDObject jsonLdObject, DataIntegrityProof dataIntegrityProof) throws IOException, GeneralSecurityException, JsonLDException {
5151

5252
// check the proof object
5353

@@ -73,24 +73,32 @@ public boolean verify(JsonLDObject jsonLdObject, DataIntegrityProof dataIntegrit
7373

7474
// verify
7575

76-
boolean verify = this.verify(canonicalizationResult, ldProofOptions);
77-
if (log.isDebugEnabled()) log.debug("Verified data integrity proof: {} --> {}", dataIntegrityProof, verify);
76+
boolean verified = this.verify(canonicalizationResult, ldProofOptions);
77+
if (log.isDebugEnabled()) log.debug("Verified data integrity proof: {} --> {}", dataIntegrityProof, verified);
7878

7979
// done
8080

81-
return verify;
81+
return new LdVerifierResult(dataIntegrityProof, ldProofOptions, canonicalizer, canonicalizationResult, verified);
8282
}
8383

84-
public boolean verify(JsonLDObject jsonLdObject) throws IOException, GeneralSecurityException, JsonLDException {
84+
public LdVerifierResult verifyWithResult(JsonLDObject jsonLdObject) throws IOException, GeneralSecurityException, JsonLDException {
8585

8686
// obtain the signature object
8787

8888
DataIntegrityProof dataIntegrityProof = DataIntegrityProof.getFromJsonLDObject(jsonLdObject);
89-
if (dataIntegrityProof == null) return false;
89+
if (dataIntegrityProof == null) return new LdVerifierResult(dataIntegrityProof, null, null, null, false);
9090

9191
// done
9292

93-
return this.verify(jsonLdObject, dataIntegrityProof);
93+
return this.verifyWithResult(jsonLdObject, dataIntegrityProof);
94+
}
95+
96+
public boolean verify(JsonLDObject jsonLdObject, DataIntegrityProof dataIntegrityProof) throws IOException, GeneralSecurityException, JsonLDException {
97+
return this.verifyWithResult(jsonLdObject, dataIntegrityProof).verified();
98+
}
99+
100+
public boolean verify(JsonLDObject jsonLdObject) throws IOException, GeneralSecurityException, JsonLDException {
101+
return this.verifyWithResult(jsonLdObject).verified();
94102
}
95103

96104
public void initialize(DataIntegrityProof dataIntegrityProof) throws GeneralSecurityException {
@@ -101,6 +109,13 @@ public void initialize(DataIntegrityProof dataIntegrityProof) throws GeneralSecu
101109

102110
public abstract Canonicalizer getCanonicalizer(DataIntegrityProof dataIntegrityProof);
103111

112+
/*
113+
* Helper records
114+
*/
115+
116+
public record LdVerifierResult(DataIntegrityProof dataIntegrityProof, DataIntegrityProof ldProofOptions, Canonicalizer canonicalizer, byte[] canonicalizationResult, boolean verified) {
117+
}
118+
104119
/*
105120
* Getters and setters
106121
*/

0 commit comments

Comments
 (0)