Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a class that does all hex encoding #213

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions sdk/src/main/java/io/opentdf/platform/sdk/HexString.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.opentdf.platform.sdk;

import org.apache.commons.codec.binary.Hex;

public class HexString {
private final byte[] value;

public HexString(byte[] value) {
this.value = value;
}

byte[] byteValue() { return value; }
}
5 changes: 2 additions & 3 deletions sdk/src/main/java/io/opentdf/platform/sdk/Manifest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import io.opentdf.platform.sdk.TDF.AssertionException;

import org.apache.commons.codec.binary.Hex;
import org.erdtman.jcs.JsonCanonicalizer;

import java.io.IOException;
Expand Down Expand Up @@ -343,7 +342,7 @@ public int hashCode() {
return Objects.hash(id, type, scope, appliesToState, statement, binding);
}

public String hash() throws IOException {
public HexString hash() throws IOException {
MessageDigest digest;
try {
digest = MessageDigest.getInstance("SHA-256");
Expand All @@ -353,7 +352,7 @@ public String hash() throws IOException {

var assertionAsJson = gson.toJson(this);
JsonCanonicalizer jc = new JsonCanonicalizer(assertionAsJson);
return Hex.encodeHexString(digest.digest(jc.getEncodedUTF8()));
return new HexString(digest.digest(jc.getEncodedUTF8()));
}

// Sign the assertion with the given hash and signature using the key.
Expand Down
Loading
Loading