Skip to content

Commit

Permalink
feat(core): NanoTDF resource locator protocol bit mask (#107)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pflynn-virtru authored Aug 7, 2024
1 parent 785c314 commit 159d2f1
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public ResourceLocator(String resourceUrl) {
}

public ResourceLocator(ByteBuffer buffer) {
this.protocol = NanoTDFType.Protocol.values()[buffer.get()];
// Get the first byte and mask it with 0xF to keep only the first four bits
byte protocolByte = buffer.get();
int protocolIndex = protocolByte & 0xF;
this.protocol = NanoTDFType.Protocol.values()[protocolIndex];
this.bodyLength = buffer.get();
this.body = new byte[this.bodyLength];
buffer.get(this.body);
Expand Down

0 comments on commit 159d2f1

Please sign in to comment.