Hey all - Admittedly, Java is not my strong suit.
I’m working with the tiny version of the openjavacard-ndef project, where, at the install method, the details for the parameter provided during the app install are identified by the offset:
public static void install(byte[] buf, short off, byte len) {
short pos = off;
// find AID
byte lenAID = buf[pos++];
short offAID = pos;
pos += lenAID;
// find control information (ignored)
byte lenCI = buf[pos++];
short offCI = pos;
pos += lenCI;
// find applet data
byte lenAD = buf[pos++];
short offAD = pos;
pos += lenAD;
// instantiate and initialize the applet
NdefApplet applet = new NdefApplet(buf, offAD, lenAD);
// register the applet
applet.register(buf, offAID, lenAID);
}
I have an alternate version, where I’m attempting to append hardcoded text to what is received from the parameter, which looks like this:
public static void install(byte[] buf, short off, byte len) {
short pos = off;
// find AID
byte lenAID = buf[pos++];
short offAID = pos;
pos += lenAID;
// find control information (ignored)
byte lenCI = buf[pos++];
short offCI = pos;
pos += lenCI;
// find applet data
byte lenAD = buf[pos++];
short offAD = pos;
pos += lenAD;
// appending
byte [] paramData = new byte[lenAD];
Util.arrayCopyNonAtomic(buf, offAD, paramData, (short) 0, lenAD);
byte[] scanSuffix = {
};
short appendedLength = (short) (lenAD + scanSuffix.length);
byte[] appendedData = new byte[appendedLength];
Util.arrayCopyNonAtomic(paramData, (short) 0, appendedData, (short) 0, lenAD);
Util.arrayCopyNonAtomic(scanSuffix, (short) 0, appendedData, lenAD, (short) scanSuffix.length);
NdefApplet applet = new NdefApplet(appendedData, (short) 0, (byte) appendedLength);
// register the applet
applet.register();
}
This works without an issue. However, I cannot seem to add content to the scanSuffix variable. I had assumed I could do either:
byte[] scanSuffix = {(byte) 0xAA, (byte) 0xBB};
// or
byte[] scanSuffix = {(byte) 'a', (byte) 'b'};
Either of these convert and install fine, but do not work as expected.
My questions are:
- Is there a functional problem with the way I’m adding to the parameter data?
- I understand the Tiny variant prevents re-writing of tags, etc. I understood this as after the tag has been installed. Would this have any impact on adding hardcoded text at install time?
I know this isn’t a support forum for java coding, but figured I’d ask