Skip to content

Commit 72033fb

Browse files
committed
Add logging
1 parent 5326809 commit 72033fb

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

src/main/java/com/danubetech/dataintegrity/signer/DataIntegrityProofLdSigner.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
import com.danubetech.dataintegrity.suites.DataIntegritySuites;
88
import com.danubetech.keyformats.crypto.ByteSigner;
99
import io.ipfs.multibase.Multibase;
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
1012

1113
import java.security.GeneralSecurityException;
1214

1315
public class DataIntegrityProofLdSigner extends LdSigner<DataIntegrityProofDataIntegritySuite> {
1416

17+
private static final Logger log = LoggerFactory.getLogger(DataIntegrityProofLdSigner.class);
18+
1519
public DataIntegrityProofLdSigner(ByteSigner signer) {
1620
super(DataIntegritySuites.DATA_INTEGRITY_SUITE_DATAINTEGRITYPROOF, signer);
1721
}
@@ -43,6 +47,7 @@ public static void sign(DataIntegrityProof.Builder<? extends DataIntegrityProof.
4347
cryptosuite = DataIntegrityProofDataIntegritySuite.findDefaultCryptosuiteByJwsAlgorithm(algorithm);
4448
ldProofBuilder.cryptosuite(cryptosuite);
4549
}
50+
if (log.isDebugEnabled()) log.debug("Determined algorithm {} and cryptosuite: {}", algorithm, cryptosuite);
4651

4752
// sign
4853

src/main/java/com/danubetech/dataintegrity/signer/LdSigner.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import foundation.identity.jsonld.JsonLDException;
99
import foundation.identity.jsonld.JsonLDObject;
1010
import foundation.identity.jsonld.JsonLDUtils;
11+
import org.apache.commons.codec.binary.Hex;
12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
1114

1215
import java.io.IOException;
1316
import java.net.URI;
@@ -16,6 +19,8 @@
1619

1720
public abstract class LdSigner<DATAINTEGRITYSUITE extends DataIntegritySuite> {
1821

22+
private static final Logger log = LoggerFactory.getLogger(LdSigner.class);
23+
1924
private final DATAINTEGRITYSUITE dataIntegritySuite;
2025

2126
private ByteSigner signer;
@@ -86,14 +91,17 @@ public DataIntegrityProof sign(JsonLDObject jsonLdObject, boolean addToJsonLdObj
8691
.proofPurpose(this.getProofPurpose())
8792
.previousProof(this.getPreviousProof())
8893
.build();
94+
if (log.isDebugEnabled()) log.debug("Constructed data integrity proof: {}", dataIntegrityProof);
8995

9096
// add missing context(s)
9197

9298
loadMissingContext(jsonLdObject);
9399

94100
// obtain the canonicalized document
95101

96-
byte[] canonicalizationResult = this.getCanonicalizer(dataIntegrityProof).canonicalize(dataIntegrityProof, jsonLdObject);
102+
Canonicalizer canonicalizer = this.getCanonicalizer(dataIntegrityProof);
103+
byte[] canonicalizationResult = canonicalizer.canonicalize(dataIntegrityProof, jsonLdObject);
104+
if (log.isDebugEnabled()) log.debug("Canonicalization result with {}: {}", canonicalizer.getClass().getSimpleName(), Hex.encodeHex(canonicalizationResult));
97105

98106
// sign
99107

@@ -103,6 +111,7 @@ public DataIntegrityProof sign(JsonLDObject jsonLdObject, boolean addToJsonLdObj
103111
this.sign(ldProofBuilder, canonicalizationResult);
104112

105113
dataIntegrityProof = ldProofBuilder.build();
114+
if (log.isDebugEnabled()) log.debug("Signed data integrity proof: {}", dataIntegrityProof);
106115

107116
// add proof to JSON-LD
108117

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
import com.danubetech.dataintegrity.suites.DataIntegritySuites;
88
import com.danubetech.keyformats.crypto.ByteVerifier;
99
import io.ipfs.multibase.Multibase;
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
1012

1113
import java.security.GeneralSecurityException;
1214

1315
public class DataIntegrityProofLdVerifier extends LdVerifier<DataIntegrityProofDataIntegritySuite> {
1416

17+
private static final Logger log = LoggerFactory.getLogger(DataIntegrityProofLdVerifier.class);
18+
1519
public DataIntegrityProofLdVerifier(ByteVerifier verifier) {
1620
super(DataIntegritySuites.DATA_INTEGRITY_SUITE_DATAINTEGRITYPROOF, verifier);
1721
}
@@ -41,6 +45,7 @@ public static boolean verify(byte[] signingInput, DataIntegrityProof dataIntegri
4145
if (! DataIntegrityProofDataIntegritySuite.findCryptosuitesByJwsAlgorithm(algorithm).contains(cryptosuite)) {
4246
throw new GeneralSecurityException("Algorithm " + algorithm + " is not supported by cryptosuite " + cryptosuite);
4347
}
48+
if (log.isDebugEnabled()) log.debug("Determined algorithm {} and cryptosuite: {}", algorithm, cryptosuite);
4449

4550
// verify
4651

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@
66
import com.danubetech.keyformats.crypto.ByteVerifier;
77
import foundation.identity.jsonld.JsonLDException;
88
import foundation.identity.jsonld.JsonLDObject;
9+
import org.apache.commons.codec.binary.Hex;
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
912

1013
import java.io.IOException;
1114
import java.security.GeneralSecurityException;
1215

1316
public abstract class LdVerifier<DATAINTEGRITYSUITE extends DataIntegritySuite> {
1417

18+
private static final Logger log = LoggerFactory.getLogger(LdVerifier.class);
19+
1520
private final DATAINTEGRITYSUITE dataIntegritySuite;
1621

1722
private ByteVerifier verifier;
@@ -50,11 +55,14 @@ public boolean verify(JsonLDObject jsonLdObject, DataIntegrityProof dataIntegrit
5055

5156
// obtain the canonicalized document
5257

58+
Canonicalizer canonicalizer = this.getCanonicalizer(dataIntegrityProof);
5359
byte[] canonicalizationResult = this.getCanonicalizer(dataIntegrityProof).canonicalize(dataIntegrityProof, jsonLdObject);
60+
if (log.isDebugEnabled()) log.debug("Canonicalization result with {}: {}", canonicalizer.getClass().getSimpleName(), Hex.encodeHex(canonicalizationResult));
5461

5562
// verify
5663

5764
boolean verify = this.verify(canonicalizationResult, dataIntegrityProof);
65+
if (log.isDebugEnabled()) log.debug("Verified data integrity proof: {} --> {}", dataIntegrityProof, verify);
5866

5967
// done
6068

0 commit comments

Comments
 (0)