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>com.oracle.javacard.jcdk.core.projectbuild.JCDKNature</nature>
|
||||
</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>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
package hwb1;
|
||||
|
||||
import javacard.framework.*;
|
||||
|
@ -18,10 +17,11 @@ import static hwb1.MyAppletStrings.*;
|
|||
@StringPool(value = {
|
||||
@StringDef(name = "Package", value = "hwb1"),
|
||||
@StringDef(name = "AppletName", value = "MyApplet"),
|
||||
@StringDef(name = "AuthorName", value = "Manuel")},
|
||||
@StringDef(name = "AuthorName", value = "Manuel") },
|
||||
// Insert your strings here
|
||||
name = "MyAppletStrings")
|
||||
public class MyApplet extends Applet {
|
||||
private byte[] storage = null;
|
||||
|
||||
/**
|
||||
* Installs this applet.
|
||||
|
@ -53,21 +53,31 @@ public class MyApplet extends Applet {
|
|||
*/
|
||||
@Override
|
||||
public void process(APDU apdu) {
|
||||
short responseLength;
|
||||
short length;
|
||||
byte[] buffer = apdu.getBuffer();
|
||||
|
||||
byte instruction = buffer[ISO7816.OFFSET_INS];
|
||||
|
||||
switch (instruction) {
|
||||
case 0x00:
|
||||
responseLength = apdu.setOutgoing();
|
||||
length = apdu.setOutgoing();
|
||||
|
||||
if (responseLength > MyAppletStrings.AuthorName.length) {
|
||||
responseLength = (short)MyAppletStrings.AuthorName.length;
|
||||
if (length > AuthorName.length) {
|
||||
length = (short)AuthorName.length;
|
||||
}
|
||||
|
||||
apdu.setOutgoingLength(responseLength);
|
||||
apdu.sendBytesLong(MyAppletStrings.AuthorName, (short)0, responseLength);
|
||||
apdu.setOutgoingLength(length);
|
||||
apdu.sendBytesLong(AuthorName, (short)0, length);
|
||||
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