Skip to content

Commit f89d944

Browse files
committed
chore: Whitespace
1 parent 2805a92 commit f89d944

File tree

48 files changed

+1713
-1713
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1713
-1713
lines changed

src/main/java/com/danubetech/dataintegrity/canonicalizer/Canonicalizer.java

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,36 @@
1111

1212
public abstract class Canonicalizer {
1313

14-
private final List<String> algorithms;
15-
16-
public abstract String canonicalize(JsonLDObject jsonLdObject) throws IOException, GeneralSecurityException, JsonLDException;
17-
public abstract byte[] canonicalize(DataIntegrityProof dataIntegrityProof, JsonLDObject jsonLdObject) throws IOException, GeneralSecurityException, JsonLDException;
18-
19-
public Canonicalizer(List<String> algorithms) {
20-
this.algorithms = algorithms;
21-
}
22-
23-
public List<String> getAlgorithms() {
24-
return algorithms;
25-
}
26-
27-
@Override
28-
public boolean equals(Object o) {
29-
if (this == o) return true;
30-
if (o == null || getClass() != o.getClass()) return false;
31-
Canonicalizer that = (Canonicalizer) o;
32-
return Objects.equals(algorithms, that.algorithms);
33-
}
34-
35-
@Override
36-
public int hashCode() {
37-
return Objects.hash(algorithms);
38-
}
39-
40-
@Override
41-
public String toString() {
42-
return "Canonicalizer{" +
43-
"algorithms='" + algorithms + '\'' +
44-
'}';
45-
}
14+
private final List<String> algorithms;
15+
16+
public abstract String canonicalize(JsonLDObject jsonLdObject) throws IOException, GeneralSecurityException, JsonLDException;
17+
public abstract byte[] canonicalize(DataIntegrityProof dataIntegrityProof, JsonLDObject jsonLdObject) throws IOException, GeneralSecurityException, JsonLDException;
18+
19+
public Canonicalizer(List<String> algorithms) {
20+
this.algorithms = algorithms;
21+
}
22+
23+
public List<String> getAlgorithms() {
24+
return algorithms;
25+
}
26+
27+
@Override
28+
public boolean equals(Object o) {
29+
if (this == o) return true;
30+
if (o == null || getClass() != o.getClass()) return false;
31+
Canonicalizer that = (Canonicalizer) o;
32+
return Objects.equals(algorithms, that.algorithms);
33+
}
34+
35+
@Override
36+
public int hashCode() {
37+
return Objects.hash(algorithms);
38+
}
39+
40+
@Override
41+
public String toString() {
42+
return "Canonicalizer{" +
43+
"algorithms='" + algorithms + '\'' +
44+
'}';
45+
}
4646
}

src/main/java/com/danubetech/dataintegrity/canonicalizer/Canonicalizers.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public class Canonicalizers {
3333
for (Canonicalizer canonicalizer : CANONICALIZERS) {
3434
List<String> algorithms = canonicalizer.getAlgorithms();
3535
for (String algorithm : algorithms) {
36-
List<Canonicalizer> canonicalizersList = CANONICALIZERS_BY_ALGORITHM.computeIfAbsent(algorithm, k -> new ArrayList<>());
37-
canonicalizersList.add(canonicalizer);
36+
List<Canonicalizer> canonicalizersList = CANONICALIZERS_BY_ALGORITHM.computeIfAbsent(algorithm, k -> new ArrayList<>());
37+
canonicalizersList.add(canonicalizer);
3838
}
3939
}
4040
}

src/main/java/com/danubetech/dataintegrity/canonicalizer/JCSCanonicalizer.java

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,57 +15,57 @@
1515

1616
public abstract class JCSCanonicalizer extends Canonicalizer {
1717

18-
private static final Logger log = LoggerFactory.getLogger(JCSCanonicalizer.class);
18+
private static final Logger log = LoggerFactory.getLogger(JCSCanonicalizer.class);
1919

20-
public JCSCanonicalizer() {
21-
super(List.of("jcs"));
22-
}
20+
public JCSCanonicalizer() {
21+
super(List.of("jcs"));
22+
}
2323

24-
public abstract int hashLength();
25-
public abstract byte[] hash(byte[] input) throws GeneralSecurityException;
24+
public abstract int hashLength();
25+
public abstract byte[] hash(byte[] input) throws GeneralSecurityException;
2626

27-
@Override
28-
public String canonicalize(JsonLDObject jsonLDObject) throws JsonLDException, IOException {
27+
@Override
28+
public String canonicalize(JsonLDObject jsonLDObject) throws JsonLDException, IOException {
2929

30-
return new JsonCanonicalizer(jsonLDObject.toJson()).getEncodedString();
31-
}
30+
return new JsonCanonicalizer(jsonLDObject.toJson()).getEncodedString();
31+
}
3232

33-
@Override
34-
public byte[] canonicalize(DataIntegrityProof dataIntegrityProof, JsonLDObject jsonLdObject) throws IOException, GeneralSecurityException, JsonLDException {
33+
@Override
34+
public byte[] canonicalize(DataIntegrityProof dataIntegrityProof, JsonLDObject jsonLdObject) throws IOException, GeneralSecurityException, JsonLDException {
3535

36-
// construct the LD object without proof
36+
// construct the LD object without proof
3737

38-
JsonLDObject jsonLdObjectWithoutProof = JsonLDObject.builder()
39-
.base(jsonLdObject)
40-
.build();
41-
DataIntegrityProof.removeFromJsonLdObject(jsonLdObjectWithoutProof);
38+
JsonLDObject jsonLdObjectWithoutProof = JsonLDObject.builder()
39+
.base(jsonLdObject)
40+
.build();
41+
DataIntegrityProof.removeFromJsonLdObject(jsonLdObjectWithoutProof);
4242

43-
// construct the LD proof options without proof values
43+
// construct the LD proof options without proof values
4444

45-
DataIntegrityProof dataIntegrityProofWithoutProofValues = DataIntegrityProof.builder()
46-
.base(dataIntegrityProof)
47-
.defaultContexts(false)
48-
.build();
49-
DataIntegrityProof.removeLdProofValues(dataIntegrityProofWithoutProofValues);
45+
DataIntegrityProof dataIntegrityProofWithoutProofValues = DataIntegrityProof.builder()
46+
.base(dataIntegrityProof)
47+
.defaultContexts(false)
48+
.build();
49+
DataIntegrityProof.removeLdProofValues(dataIntegrityProofWithoutProofValues);
5050

51-
// canonicalize the LD object and LD proof options
51+
// canonicalize the LD object and LD proof options
5252

53-
String canonicalizedJsonLdObjectWithoutProof = this.canonicalize(jsonLdObjectWithoutProof);
54-
byte[] canonicalizedJsonLdObjectWithoutProofHash = this.hash(canonicalizedJsonLdObjectWithoutProof.getBytes(StandardCharsets.UTF_8));
55-
if (log.isDebugEnabled()) log.debug("Canonicalized LD object without proof: {}", canonicalizedJsonLdObjectWithoutProof);
56-
if (log.isDebugEnabled()) log.debug("Hashed canonicalized LD object without proof: {}", Hex.encodeHexString(canonicalizedJsonLdObjectWithoutProofHash));
53+
String canonicalizedJsonLdObjectWithoutProof = this.canonicalize(jsonLdObjectWithoutProof);
54+
byte[] canonicalizedJsonLdObjectWithoutProofHash = this.hash(canonicalizedJsonLdObjectWithoutProof.getBytes(StandardCharsets.UTF_8));
55+
if (log.isDebugEnabled()) log.debug("Canonicalized LD object without proof: {}", canonicalizedJsonLdObjectWithoutProof);
56+
if (log.isDebugEnabled()) log.debug("Hashed canonicalized LD object without proof: {}", Hex.encodeHexString(canonicalizedJsonLdObjectWithoutProofHash));
5757

58-
String canonicalizedLdProofWithoutProofValues = this.canonicalize(dataIntegrityProofWithoutProofValues);
59-
byte[] canonicalizedLdProofWithoutProofValuesHash = this.hash(canonicalizedLdProofWithoutProofValues.getBytes(StandardCharsets.UTF_8));
60-
if (log.isDebugEnabled()) log.debug("Canonicalized LD proof without proof value: {}", canonicalizedLdProofWithoutProofValues);
61-
if (log.isDebugEnabled()) log.debug("Hashed canonicalized LD proof without proof value: {}", Hex.encodeHexString(canonicalizedLdProofWithoutProofValuesHash));
58+
String canonicalizedLdProofWithoutProofValues = this.canonicalize(dataIntegrityProofWithoutProofValues);
59+
byte[] canonicalizedLdProofWithoutProofValuesHash = this.hash(canonicalizedLdProofWithoutProofValues.getBytes(StandardCharsets.UTF_8));
60+
if (log.isDebugEnabled()) log.debug("Canonicalized LD proof without proof value: {}", canonicalizedLdProofWithoutProofValues);
61+
if (log.isDebugEnabled()) log.debug("Hashed canonicalized LD proof without proof value: {}", Hex.encodeHexString(canonicalizedLdProofWithoutProofValuesHash));
6262

63-
// construct the canonicalization result
63+
// construct the canonicalization result
6464

65-
byte[] canonicalizationResult = new byte[this.hashLength()*2];
66-
System.arraycopy(canonicalizedLdProofWithoutProofValuesHash, 0, canonicalizationResult, 0, this.hashLength());
67-
System.arraycopy(canonicalizedJsonLdObjectWithoutProofHash, 0, canonicalizationResult, this.hashLength(), this.hashLength());
65+
byte[] canonicalizationResult = new byte[this.hashLength()*2];
66+
System.arraycopy(canonicalizedLdProofWithoutProofValuesHash, 0, canonicalizationResult, 0, this.hashLength());
67+
System.arraycopy(canonicalizedJsonLdObjectWithoutProofHash, 0, canonicalizationResult, this.hashLength(), this.hashLength());
6868

69-
return canonicalizationResult;
70-
}
69+
return canonicalizationResult;
70+
}
7171
}

src/main/java/com/danubetech/dataintegrity/canonicalizer/JCSSHA256Canonicalizer.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66

77
public class JCSSHA256Canonicalizer extends JCSCanonicalizer {
88

9-
private static final JCSSHA256Canonicalizer INSTANCE = new JCSSHA256Canonicalizer();
9+
private static final JCSSHA256Canonicalizer INSTANCE = new JCSSHA256Canonicalizer();
1010

11-
public static JCSSHA256Canonicalizer getInstance() {
12-
return INSTANCE;
13-
}
11+
public static JCSSHA256Canonicalizer getInstance() {
12+
return INSTANCE;
13+
}
1414

15-
public int hashLength() {
16-
return 32;
17-
}
15+
public int hashLength() {
16+
return 32;
17+
}
1818

19-
public byte[] hash(byte[] input) throws GeneralSecurityException {
20-
return SHA256Provider.get().sha256(input);
21-
}
19+
public byte[] hash(byte[] input) throws GeneralSecurityException {
20+
return SHA256Provider.get().sha256(input);
21+
}
2222
}

src/main/java/com/danubetech/dataintegrity/canonicalizer/JCSSHA384Canonicalizer.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66

77
public class JCSSHA384Canonicalizer extends JCSCanonicalizer {
88

9-
private static final JCSSHA384Canonicalizer INSTANCE = new JCSSHA384Canonicalizer();
9+
private static final JCSSHA384Canonicalizer INSTANCE = new JCSSHA384Canonicalizer();
1010

11-
public static JCSSHA384Canonicalizer getInstance() {
12-
return INSTANCE;
13-
}
11+
public static JCSSHA384Canonicalizer getInstance() {
12+
return INSTANCE;
13+
}
1414

15-
public int hashLength() {
16-
return 48;
17-
}
15+
public int hashLength() {
16+
return 48;
17+
}
1818

19-
public byte[] hash(byte[] input) throws GeneralSecurityException {
20-
return SHA384Provider.get().sha384(input);
21-
}
19+
public byte[] hash(byte[] input) throws GeneralSecurityException {
20+
return SHA384Provider.get().sha384(input);
21+
}
2222
}

src/main/java/com/danubetech/dataintegrity/canonicalizer/JCSSHA512Canonicalizer.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66

77
public class JCSSHA512Canonicalizer extends JCSCanonicalizer {
88

9-
private static final JCSSHA512Canonicalizer INSTANCE = new JCSSHA512Canonicalizer();
9+
private static final JCSSHA512Canonicalizer INSTANCE = new JCSSHA512Canonicalizer();
1010

11-
public static JCSSHA512Canonicalizer getInstance() {
12-
return INSTANCE;
13-
}
11+
public static JCSSHA512Canonicalizer getInstance() {
12+
return INSTANCE;
13+
}
1414

15-
public int hashLength() {
16-
return 64;
17-
}
15+
public int hashLength() {
16+
return 64;
17+
}
1818

19-
public byte[] hash(byte[] input) throws GeneralSecurityException {
20-
return SHA512Provider.get().sha512(input);
21-
}
19+
public byte[] hash(byte[] input) throws GeneralSecurityException {
20+
return SHA512Provider.get().sha512(input);
21+
}
2222
}

src/main/java/com/danubetech/dataintegrity/canonicalizer/RDFC10Canonicalizer.java

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -20,71 +20,71 @@
2020

2121
public abstract class RDFC10Canonicalizer extends Canonicalizer {
2222

23-
private static final Logger log = LoggerFactory.getLogger(RDFC10Canonicalizer.class);
23+
private static final Logger log = LoggerFactory.getLogger(RDFC10Canonicalizer.class);
2424

25-
public RDFC10Canonicalizer() {
26-
super(List.of("RDFC-1.0"));
27-
}
25+
public RDFC10Canonicalizer() {
26+
super(List.of("RDFC-1.0"));
27+
}
2828

29-
public abstract String hashAlgorithm();
30-
public abstract int hashLength();
31-
public abstract byte[] hash(byte[] input) throws GeneralSecurityException;
29+
public abstract String hashAlgorithm();
30+
public abstract int hashLength();
31+
public abstract byte[] hash(byte[] input) throws GeneralSecurityException;
3232

33-
@Override
34-
public String canonicalize(JsonLDObject jsonLDObject) throws JsonLDException, IOException {
35-
RdfCanon rdfCanon = RdfCanon.create(this.hashAlgorithm());
36-
StringWriter stringWriter = new StringWriter();
37-
RdfQuadConsumer nQuadsWriter = new NQuadsWriter(stringWriter);
33+
@Override
34+
public String canonicalize(JsonLDObject jsonLDObject) throws JsonLDException, IOException {
35+
RdfCanon rdfCanon = RdfCanon.create(this.hashAlgorithm());
36+
StringWriter stringWriter = new StringWriter();
37+
RdfQuadConsumer nQuadsWriter = new NQuadsWriter(stringWriter);
3838

39-
try {
40-
jsonLDObject.toRdfApi().provide(rdfCanon);
41-
rdfCanon.provide(nQuadsWriter);
42-
} catch (RdfConsumerException ex) {
43-
throw new IOException("Cannot consume RDF: " + ex.getMessage(), ex);
44-
} catch (JsonLdError ex) {
45-
throw new JsonLDException(ex);
46-
}
39+
try {
40+
jsonLDObject.toRdfApi().provide(rdfCanon);
41+
rdfCanon.provide(nQuadsWriter);
42+
} catch (RdfConsumerException ex) {
43+
throw new IOException("Cannot consume RDF: " + ex.getMessage(), ex);
44+
} catch (JsonLdError ex) {
45+
throw new JsonLDException(ex);
46+
}
4747

48-
return stringWriter.getBuffer().toString();
49-
}
48+
return stringWriter.getBuffer().toString();
49+
}
5050

51-
@Override
52-
public byte[] canonicalize(DataIntegrityProof dataIntegrityProof, JsonLDObject jsonLdObject) throws IOException, GeneralSecurityException, JsonLDException {
51+
@Override
52+
public byte[] canonicalize(DataIntegrityProof dataIntegrityProof, JsonLDObject jsonLdObject) throws IOException, GeneralSecurityException, JsonLDException {
5353

54-
// construct the LD object without proof
54+
// construct the LD object without proof
5555

56-
JsonLDObject jsonLdObjectWithoutProof = JsonLDObject.builder()
57-
.base(jsonLdObject)
58-
.build();
59-
DataIntegrityProof.removeFromJsonLdObject(jsonLdObjectWithoutProof);
56+
JsonLDObject jsonLdObjectWithoutProof = JsonLDObject.builder()
57+
.base(jsonLdObject)
58+
.build();
59+
DataIntegrityProof.removeFromJsonLdObject(jsonLdObjectWithoutProof);
6060

61-
// construct the LD proof options without proof values
61+
// construct the LD proof options without proof values
6262

63-
DataIntegrityProof dataIntegrityProofWithoutProofValues = DataIntegrityProof.builder()
64-
.base(dataIntegrityProof)
65-
.build();
66-
DataIntegrityProof.removeLdProofValues(dataIntegrityProofWithoutProofValues);
63+
DataIntegrityProof dataIntegrityProofWithoutProofValues = DataIntegrityProof.builder()
64+
.base(dataIntegrityProof)
65+
.build();
66+
DataIntegrityProof.removeLdProofValues(dataIntegrityProofWithoutProofValues);
6767

68-
// canonicalize the LD object and LD proof options
68+
// canonicalize the LD object and LD proof options
6969

70-
jsonLdObjectWithoutProof.setDocumentLoader(jsonLdObject.getDocumentLoader());
71-
String canonicalizedJsonLdObjectWithoutProof = this.canonicalize(jsonLdObjectWithoutProof);
72-
byte[] canonicalizedJsonLdObjectWithoutProofHash = this.hash(canonicalizedJsonLdObjectWithoutProof.getBytes(StandardCharsets.UTF_8));
73-
if (log.isDebugEnabled()) log.debug("Canonicalized LD object without proof: {}", canonicalizedJsonLdObjectWithoutProof);
74-
if (log.isDebugEnabled()) log.debug("Hashed canonicalized LD object without proof: {}", Hex.encodeHexString(canonicalizedJsonLdObjectWithoutProofHash));
70+
jsonLdObjectWithoutProof.setDocumentLoader(jsonLdObject.getDocumentLoader());
71+
String canonicalizedJsonLdObjectWithoutProof = this.canonicalize(jsonLdObjectWithoutProof);
72+
byte[] canonicalizedJsonLdObjectWithoutProofHash = this.hash(canonicalizedJsonLdObjectWithoutProof.getBytes(StandardCharsets.UTF_8));
73+
if (log.isDebugEnabled()) log.debug("Canonicalized LD object without proof: {}", canonicalizedJsonLdObjectWithoutProof);
74+
if (log.isDebugEnabled()) log.debug("Hashed canonicalized LD object without proof: {}", Hex.encodeHexString(canonicalizedJsonLdObjectWithoutProofHash));
7575

76-
dataIntegrityProofWithoutProofValues.setDocumentLoader(jsonLdObject.getDocumentLoader());
77-
String canonicalizedLdProofWithoutProofValues = this.canonicalize(dataIntegrityProofWithoutProofValues);
78-
byte[] canonicalizedLdProofWithoutProofValuesHash = this.hash(canonicalizedLdProofWithoutProofValues.getBytes(StandardCharsets.UTF_8));
79-
if (log.isDebugEnabled()) log.debug("Canonicalized LD proof without proof value: {}", canonicalizedLdProofWithoutProofValues);
80-
if (log.isDebugEnabled()) log.debug("Hashed canonicalized LD proof without proof value: {}", Hex.encodeHexString(canonicalizedLdProofWithoutProofValuesHash));
76+
dataIntegrityProofWithoutProofValues.setDocumentLoader(jsonLdObject.getDocumentLoader());
77+
String canonicalizedLdProofWithoutProofValues = this.canonicalize(dataIntegrityProofWithoutProofValues);
78+
byte[] canonicalizedLdProofWithoutProofValuesHash = this.hash(canonicalizedLdProofWithoutProofValues.getBytes(StandardCharsets.UTF_8));
79+
if (log.isDebugEnabled()) log.debug("Canonicalized LD proof without proof value: {}", canonicalizedLdProofWithoutProofValues);
80+
if (log.isDebugEnabled()) log.debug("Hashed canonicalized LD proof without proof value: {}", Hex.encodeHexString(canonicalizedLdProofWithoutProofValuesHash));
8181

82-
// construct the canonicalization result
82+
// construct the canonicalization result
8383

84-
byte[] canonicalizationResult = new byte[this.hashLength()*2];
85-
System.arraycopy(canonicalizedLdProofWithoutProofValuesHash, 0, canonicalizationResult, 0, this.hashLength());
86-
System.arraycopy(canonicalizedJsonLdObjectWithoutProofHash, 0, canonicalizationResult, this.hashLength(), this.hashLength());
84+
byte[] canonicalizationResult = new byte[this.hashLength()*2];
85+
System.arraycopy(canonicalizedLdProofWithoutProofValuesHash, 0, canonicalizationResult, 0, this.hashLength());
86+
System.arraycopy(canonicalizedJsonLdObjectWithoutProofHash, 0, canonicalizationResult, this.hashLength(), this.hashLength());
8787

88-
return canonicalizationResult;
89-
}
88+
return canonicalizationResult;
89+
}
9090
}

0 commit comments

Comments
 (0)