Add instruction for storing data

This commit is contained in:
Manuel Thalmann 2023-10-12 20:13:26 +02:00
parent 8f7e657a9c
commit a673b7ecd0
2 changed files with 48 additions and 27 deletions

View file

@ -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>

View file

@ -3,7 +3,6 @@
*
*/
package hwb1;
import javacard.framework.*;
@ -22,6 +21,7 @@ import static hwb1.MyAppletStrings.*;
// 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;
}
}