Skip to content

Commit 159d2f1

Browse files
feat(core): NanoTDF resource locator protocol bit mask (#107)
This is prep for the incoming changes related to ADR below. Updated the constructor to mask the first byte with 0xF, ensuring only the first four bits are used for indexing the protocol. This prevents potential out-of-bounds errors when retrieving values from the NanoTDFType.Protocol enum. Issue: opentdf/platform#1203 Specification: opentdf/spec#40 ADR: opentdf/platform#900
1 parent 785c314 commit 159d2f1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

sdk/src/main/java/io/opentdf/platform/sdk/nanotdf/ResourceLocator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ public ResourceLocator(String resourceUrl) {
2525
}
2626

2727
public ResourceLocator(ByteBuffer buffer) {
28-
this.protocol = NanoTDFType.Protocol.values()[buffer.get()];
28+
// Get the first byte and mask it with 0xF to keep only the first four bits
29+
byte protocolByte = buffer.get();
30+
int protocolIndex = protocolByte & 0xF;
31+
this.protocol = NanoTDFType.Protocol.values()[protocolIndex];
2932
this.bodyLength = buffer.get();
3033
this.body = new byte[this.bodyLength];
3134
buffer.get(this.body);

0 commit comments

Comments
 (0)