我是javacard小程序编程的新手,并试图理解
shareable
接口来调用另一个小程序中的小程序方法。下面是我的设置
sourceapplet.java
是实现我的共享界面的小程序。从 targetapplet.java
我正在尝试调用该接口。
sourceapplet.java
public void checkNumber(byte[] number) {
short numberLength = (short)number.length;
if (numberLength < 6) {
ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
}
ISOException.throwIt(ISO7816.SW_WRONG_DATA);
}
Configurations.java
public interface Configuration extends Shareable {
public void checkNumber(byte[] number);
}
targetapplet.java
public final class TargetApplet extends Applet implements MultiSelectable {
private static final byte INS_TEST_CHECK_NUMBER = (byte) 0x11;
private AID checkNumberAppletAID;
private TargetApplet() {
// Initialize the AID of the checkNumberApplet
byte[] aidBytes = {(byte) 0xB2, 0x86, 0x00, 0x00, 0x00, 0x01};
checkNumberAppletAID = JCSystem.lookupAID(aidBytes, (short)0, (byte) aidBytes.length);
if (checkNumberAppletAID == null) {
ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND); // Applet not found
}
}
public void process(APDU apdu) {
final byte[] buffer = apdu.getBuffer();
final byte ins = buffer[ISO7816.OFFSET_INS];
switch (ins) {
case INS_TEST_CHECK_NUMBER:
processCheckNumber(apdu);
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
private void processCheckNumber(APDU apdu) {
Configuration config = (Configuration) JCSystem.getAppletShareableInterfaceObject(checkNumberAppletAID, (byte) 0x00);
if (config == null) {
ISOException.throwIt(ISO7816.SW_APPLET_SELECT_FAILED);
}
byte[] number = new byte[]{1,2,3,4};
// byte[] number = new byte[] {(byte) '1', (byte) '2', (byte) '3', (byte) '4'};
config.checkNumber(number);
}
}
现在,当我发送 apdu
00 11 00 00
时,我得到 6F00 (SW_UNKNWON)
响应,但我希望得到 SW_CONDITIONS_NOT_SATISFIED
响应。但是,当我不对 number
方法中传递的 checkNumber
数组执行任何操作时,我会得到预期的 SW_WRONG_DATA
响应。
public void checkNumber(byte[] number) {
/* short numberLength = (short)number.length;
if (numberLength < 6) {
ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
} */
ISOException.throwIt(ISO7816.SW_WRONG_DATA);
}
任何人都可以告诉我这里有什么问题以及如何解决它吗?
processCheckNumber
中传入的数字数组有问题吗?提前致谢。
P.S:如果缺少任何信息,请告诉我