Skip to content

Commit 0844225

Browse files
committed
assertions on manifest and hex chars
1 parent 252c909 commit 0844225

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

sdk/src/test/java/io/opentdf/platform/sdk/TDFTest.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import io.opentdf.platform.sdk.nanotdf.NanoTDFType;
88
import org.apache.commons.codec.DecoderException;
99
import org.apache.commons.compress.utils.SeekableInMemoryByteChannel;
10-
import org.bouncycastle.jce.interfaces.ECPrivateKey;
1110
import org.junit.jupiter.api.BeforeAll;
1211
import org.junit.jupiter.api.Test;
1312

@@ -519,6 +518,22 @@ public void legacyTDFRoundTrips() throws DecoderException, IOException, Executio
519518
var dataOutputStream = new ByteArrayOutputStream();
520519

521520
var reader = tdf.loadTDF(new SeekableInMemoryByteChannel(tdfOutputStream.toByteArray()), kas);
521+
var integrityInformation = reader.getManifest().encryptionInformation.integrityInformation;
522+
assertThat(reader.getManifest().tdfVersion).isNull();
523+
var decodedSignature = Base64.getDecoder().decode(integrityInformation.rootSignature.signature);
524+
for (var b: decodedSignature) {
525+
assertThat(isHexChar(b))
526+
.withFailMessage("non-hex byte in signature: " + b)
527+
.isTrue();
528+
}
529+
for (var s: integrityInformation.segments) {
530+
var decodedSegmentSignature = Base64.getDecoder().decode(s.hash);
531+
for (var b: decodedSegmentSignature) {
532+
assertThat(isHexChar(b))
533+
.withFailMessage("non-hex byte in segment signature: " + b)
534+
.isTrue();
535+
}
536+
}
522537
reader.readPayload(dataOutputStream);
523538
assertThat(reader.getManifest().payload.mimeType).isEqualTo(mimeType);
524539
assertArrayEquals(data, dataOutputStream.toByteArray(), "extracted data does not match");
@@ -547,4 +562,8 @@ private static Config.KASInfo[] getRSAKASInfos() {
547562
private static Config.KASInfo[] getECKASInfos() {
548563
return getKASInfos(i -> i % 2 != 0);
549564
}
565+
566+
private static boolean isHexChar(byte b) {
567+
return (b >= 'a' && b <= 'f') || (b >= '0' && b <= '9');
568+
}
550569
}

0 commit comments

Comments
 (0)