Reputation: 697
I wrote an applet for my java card and I want to send the arguments of install
method to the CAD. so I defined two static variables named theArray and arrayLength in my applet. And after that I made a copy of the install
method arguments inside the body of that method. Finally I tried to return this variables to CAD in the process
method. But in the response of SELECT
command, the card returns SW=6F00
.
package bArrayAccessibilty;
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISOException;
import javacard.framework.Util;
public class BArrayReturner extends Applet {
public static byte[] theArray;
public static short arrayLength;
private BArrayReturner() {
}
public static void install(byte bArray[], short bOffset, byte bLength)
throws ISOException {
new BArrayReturner().register();
BArrayReturner.arrayLength=(short)bArray.length;
Util.arrayCopyNonAtomic(bArray, (short)0,BArrayReturner.theArray , (short) 0, BArrayReturner.arrayLength);
}
public void process(APDU apdu) throws ISOException {
byte[] buffer=apdu.getBuffer();
Util.arrayCopyNonAtomic(BArrayReturner.theArray, (short)0,buffer , (short) 0, BArrayReturner.arrayLength);
apdu.setOutgoingAndSend((short)0, (short)255);
}
Note that, Initialization of the static fields, doesn't change anything.
I mean, I tried this lines in the class body also :
public static byte[] theArray=null;
public static short arrayLength=0;
But nothing changed.
What is wrong in my program?
Upvotes: 0
Views: 165
Reputation: 2647
The install method gets called when you install te applet.
The process method gets called when you (select first and)send a command to an instantiated/installed applet.
This means that the install method will get called first and thus:
your first error is tat you want to write to an uninitialized array(theArray == null)
your second error is the wrong parameters for Util.arrayCopyNonAtomic(take care for the offsetParameter handed over by the install method)
Upvotes: 2