|
20 | 20 |
|
21 | 21 | public abstract class RDFC10Canonicalizer extends Canonicalizer { |
22 | 22 |
|
23 | | - private static final Logger log = LoggerFactory.getLogger(RDFC10Canonicalizer.class); |
| 23 | + private static final Logger log = LoggerFactory.getLogger(RDFC10Canonicalizer.class); |
24 | 24 |
|
25 | | - public RDFC10Canonicalizer() { |
26 | | - super(List.of("RDFC-1.0")); |
27 | | - } |
| 25 | + public RDFC10Canonicalizer() { |
| 26 | + super(List.of("RDFC-1.0")); |
| 27 | + } |
28 | 28 |
|
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; |
32 | 32 |
|
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); |
38 | 38 |
|
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 | + } |
47 | 47 |
|
48 | | - return stringWriter.getBuffer().toString(); |
49 | | - } |
| 48 | + return stringWriter.getBuffer().toString(); |
| 49 | + } |
50 | 50 |
|
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 { |
53 | 53 |
|
54 | | - // construct the LD object without proof |
| 54 | + // construct the LD object without proof |
55 | 55 |
|
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); |
60 | 60 |
|
61 | | - // construct the LD proof options without proof values |
| 61 | + // construct the LD proof options without proof values |
62 | 62 |
|
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); |
67 | 67 |
|
68 | | - // canonicalize the LD object and LD proof options |
| 68 | + // canonicalize the LD object and LD proof options |
69 | 69 |
|
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)); |
75 | 75 |
|
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)); |
81 | 81 |
|
82 | | - // construct the canonicalization result |
| 82 | + // construct the canonicalization result |
83 | 83 |
|
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()); |
87 | 87 |
|
88 | | - return canonicalizationResult; |
89 | | - } |
| 88 | + return canonicalizationResult; |
| 89 | + } |
90 | 90 | } |
0 commit comments