Skip to content

Commit d6cbb90

Browse files
committed
use schema to determine assertion binder and validator
Signed-off-by: Scott Hamrick <2623452+cshamrick@users.noreply.github.com>
1 parent 65980f8 commit d6cbb90

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

sdk/src/main/java/io/opentdf/platform/sdk/Config.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public static class TDFConfig {
205205
public boolean hexEncodeRootAndSegmentHashes;
206206
public boolean renderVersionInfoInManifest;
207207
public boolean systemMetadataAssertion;
208-
public List<AssertionBinder> binders = new ArrayList<>();
208+
public Map<String, AssertionBinder> binders = new HashMap<>();
209209

210210
public TDFConfig() {
211211
this.autoconfigure = true;
@@ -304,8 +304,8 @@ public static Consumer<TDFConfig> withAssertionConfig(io.opentdf.platform.sdk.As
304304
};
305305
}
306306

307-
public static Consumer<TDFConfig> withAssertionBinder(AssertionBinder binder) {
308-
return (TDFConfig config) -> config.binders.add(binder);
307+
public static Consumer<TDFConfig> withAssertionBinder(String schema, AssertionBinder binder) {
308+
return (TDFConfig config) -> config.binders.put(schema, binder);
309309
}
310310

311311
public static Consumer<TDFConfig> withMetaData(String metaData) {

sdk/src/main/java/io/opentdf/platform/sdk/TDF.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,8 @@ TDFObject createTDF(InputStream payload, OutputStream outputStream, Config.TDFCo
505505
}
506506

507507
for (var assertionConfig : tdfConfig.assertionConfigList) {
508+
509+
508510
var assertion = new Manifest.Assertion();
509511
assertion.id = assertionConfig.id;
510512
assertion.type = assertionConfig.type.toString();
@@ -538,22 +540,20 @@ TDFObject createTDF(InputStream payload, OutputStream outputStream, Config.TDFCo
538540
assertionHashAsHex,
539541
encodedHash);
540542
try {
541-
assertion.sign(hashValues, assertionSigningKey);
543+
if (tdfConfig.binders.containsKey(assertionConfig.statement.schema)) {
544+
var binder = tdfConfig.binders.get(assertionConfig.statement.schema);
545+
binder.bind(tdfObject.manifest, completeHash);
546+
signedAssertions.add(assertion);
547+
} else {
548+
assertion.sign(hashValues, assertionSigningKey);
549+
}
550+
542551
} catch (KeyLengthException e) {
543552
throw new SDKException("error signing assertion hash", e);
544553
}
545554
signedAssertions.add(assertion);
546555
}
547556

548-
for (var binder : tdfConfig.binders) {
549-
try {
550-
var assertion = binder.bind(tdfObject.manifest, aggregateHash.toByteArray());
551-
signedAssertions.add(assertion);
552-
} catch (SDK.AssertionException e) {
553-
throw new SDKException("error binding assertion", e);
554-
}
555-
}
556-
557557
tdfObject.manifest.assertions = signedAssertions;
558558
String manifestAsStr = gson.toJson(tdfObject.manifest);
559559

@@ -735,7 +735,7 @@ Reader loadTDF(SeekableByteChannel tdf, Config.TDFReaderConfig tdfReaderConfig)
735735
break;
736736
}
737737

738-
AssertionValidator validator = tdfReaderConfig.validators.get(assertion.type);
738+
AssertionValidator validator = tdfReaderConfig.validators.get(assertion.statement.schema);
739739

740740
if (validator != null) {
741741
try {

0 commit comments

Comments
 (0)