Skip to content

fix: Align identifier bytes correctly in ResourceLocator #148

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

Merged
merged 10 commits into from
Sep 13, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ public ResourceLocator(final String resourceUrl, final String identifier) {
} else if (identifierLen <= 2) {
this.identifierType = NanoTDFType.IdentifierType.TWO_BYTES;
this.identifier = new byte[NanoTDFType.IdentifierType.TWO_BYTES.getLength()];
System.arraycopy(identifier.getBytes(), 0, this.identifier, 0, identifierLen);
System.arraycopy(identifier.getBytes(), 0, this.identifier, this.identifier.length - identifierLen, identifierLen);
} else if (identifierLen <= 8) {
this.identifierType = NanoTDFType.IdentifierType.EIGHT_BYTES;
this.identifier = new byte[NanoTDFType.IdentifierType.EIGHT_BYTES.getLength()];
System.arraycopy(identifier.getBytes(), 0, this.identifier, 0, identifierLen);
System.arraycopy(identifier.getBytes(), 0, this.identifier, this.identifier.length - identifierLen, identifierLen);
} else if (identifierLen <= 32) {
this.identifierType = NanoTDFType.IdentifierType.THIRTY_TWO_BYTES;
this.identifier = new byte[NanoTDFType.IdentifierType.THIRTY_TWO_BYTES.getLength()];
System.arraycopy(identifier.getBytes(), 0, this.identifier, 0, identifierLen);
System.arraycopy(identifier.getBytes(), 0, this.identifier, this.identifier.length - identifierLen, identifierLen);
} else {
throw new IllegalArgumentException("Unsupported identifier length: " + identifierLen);
}
Expand Down Expand Up @@ -220,6 +220,7 @@ public String getIdentifierString() {
actualLength = i + 1;
}
}
return new String(this.identifier, 0, actualLength);
String identifierPadded = new String(this.identifier, 0, actualLength);
return identifierPadded.trim();
}
}
Loading