Add instruction for storing data
This commit is contained in:
parent
8f7e657a9c
commit
a673b7ecd0
|
@ -25,4 +25,15 @@
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
<nature>com.oracle.javacard.jcdk.core.projectbuild.JCDKNature</nature>
|
<nature>com.oracle.javacard.jcdk.core.projectbuild.JCDKNature</nature>
|
||||||
</natures>
|
</natures>
|
||||||
|
<filteredResources>
|
||||||
|
<filter>
|
||||||
|
<id>1697133027601</id>
|
||||||
|
<name></name>
|
||||||
|
<type>30</type>
|
||||||
|
<matcher>
|
||||||
|
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||||
|
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||||
|
</matcher>
|
||||||
|
</filter>
|
||||||
|
</filteredResources>
|
||||||
</projectDescription>
|
</projectDescription>
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
package hwb1;
|
package hwb1;
|
||||||
|
|
||||||
import javacard.framework.*;
|
import javacard.framework.*;
|
||||||
|
@ -16,22 +15,23 @@ import static hwb1.MyAppletStrings.*;
|
||||||
* @author <user>
|
* @author <user>
|
||||||
*/
|
*/
|
||||||
@StringPool(value = {
|
@StringPool(value = {
|
||||||
@StringDef(name = "Package", value = "hwb1"),
|
@StringDef(name = "Package", value = "hwb1"),
|
||||||
@StringDef(name = "AppletName", value = "MyApplet"),
|
@StringDef(name = "AppletName", value = "MyApplet"),
|
||||||
@StringDef(name = "AuthorName", value = "Manuel")},
|
@StringDef(name = "AuthorName", value = "Manuel") },
|
||||||
// Insert your strings here
|
// Insert your strings here
|
||||||
name = "MyAppletStrings")
|
name = "MyAppletStrings")
|
||||||
public class MyApplet extends Applet {
|
public class MyApplet extends Applet {
|
||||||
|
private byte[] storage = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Installs this applet.
|
* Installs this applet.
|
||||||
*
|
*
|
||||||
* @param bArray
|
* @param bArray
|
||||||
* the array containing installation parameters
|
* the array containing installation parameters
|
||||||
* @param bOffset
|
* @param bOffset
|
||||||
* the starting offset in bArray
|
* the starting offset in bArray
|
||||||
* @param bLength
|
* @param bLength
|
||||||
* the length in bytes of the parameter data in bArray
|
* the length in bytes of the parameter data in bArray
|
||||||
*/
|
*/
|
||||||
public static void install(byte[] bArray, short bOffset, byte bLength) {
|
public static void install(byte[] bArray, short bOffset, byte bLength) {
|
||||||
new MyApplet();
|
new MyApplet();
|
||||||
|
@ -49,26 +49,36 @@ public class MyApplet extends Applet {
|
||||||
*
|
*
|
||||||
* @see APDU
|
* @see APDU
|
||||||
* @param apdu
|
* @param apdu
|
||||||
* the incoming APDU
|
* the incoming APDU
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void process(APDU apdu) {
|
public void process(APDU apdu) {
|
||||||
short responseLength;
|
short length;
|
||||||
byte[] buffer = apdu.getBuffer();
|
byte[] buffer = apdu.getBuffer();
|
||||||
|
|
||||||
byte instruction = buffer[ISO7816.OFFSET_INS];
|
byte instruction = buffer[ISO7816.OFFSET_INS];
|
||||||
|
|
||||||
switch (instruction) {
|
switch (instruction) {
|
||||||
case 0x00:
|
case 0x00:
|
||||||
responseLength = apdu.setOutgoing();
|
length = apdu.setOutgoing();
|
||||||
|
|
||||||
if (responseLength > MyAppletStrings.AuthorName.length) {
|
if (length > AuthorName.length) {
|
||||||
responseLength = (short)MyAppletStrings.AuthorName.length;
|
length = (short)AuthorName.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
apdu.setOutgoingLength(responseLength);
|
apdu.setOutgoingLength(length);
|
||||||
apdu.sendBytesLong(MyAppletStrings.AuthorName, (short)0, responseLength);
|
apdu.sendBytesLong(AuthorName, (short)0, length);
|
||||||
break;
|
break;
|
||||||
}
|
case 0x02:
|
||||||
|
length = apdu.setIncomingAndReceive();
|
||||||
|
|
||||||
|
if (length > 20) {
|
||||||
|
// ToDo: Handle too much data.
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Util.arrayCopy(buffer, ISO7816.OFFSET_CDATA, storage, (short)0, length);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue