gpt4 book ai didi

java - CAP 转换器失败并显示 'unsupported int type of intermediate value, must cast value to type short or byte'

转载 作者:行者123 更新时间:2023-11-30 07:55:18 24 4
gpt4 key购买 nike

我非常接近最终使用命令行为 JCDK 2.2.2 创建 CAP 文件。我首先将源文件 Transfer.java 编译成类文件 Transfer.class,然后尝试生成 CAP 文件。一切都很好,除了我收到错误

error: line 56: smartTransfer.Transfer: unsupported int type of intermediate value, must cast intermediate value to type short or byte.

尝试从类文件构建我的 Java Card applet 时从 CAP 转换器工具。我不知道此错误的来源,因此无法将值分配给字节或短字符。

我记得当我用 JCDK 3.0.5 安装 Eclipse Neon 时,有一个未知位置的 int 错误,但小程序仍然运行。我猜是由于我系统上的 JRE。

这是我的小程序代码:

package smartTransfer;
import javacard.framework.*;

public class Transfer extends Applet {
final static byte CLASS = (byte) 0x80;
final static byte WRITE_USER_INFO_INS = 0x07;
final static byte WRITEIT_USER_INFO_INS = 0x08;
final static byte READ_USER_INFO_INS = 0x09;
final static byte READIT_USER_INFO_INS = 0x06;
final static byte SIZE_MEMORY = (short) 127;
static byte[] memory;
static byte[] memoryy;

public static void install(byte[] bArray, short bOffset, byte bLength) throws ISOException {
new Transfer().register();
memory = new byte[SIZE_MEMORY];
memoryy = new byte[SIZE_MEMORY];
}

public void process(APDU apdu)
throws ISOException {
if (selectingApplet()) return;
byte[] buffer = apdu.getBuffer();
if (buffer[ISO7816.OFFSET_CLA] !=CLASS) {
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
}
byte ins = buffer[ISO7816.OFFSET_INS];
switch (ins) {
case READ_USER_INFO_INS:
readUserInfo(apdu);
break;
case READIT_USER_INFO_INS:
readitUserInfo(apdu);
break;
case WRITE_USER_INFO_INS:
writeUserInfo(apdu);
break;
case WRITEIT_USER_INFO_INS:
writeitUserInfo(apdu);
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}

private void writeUserInfo(APDU apdu) {
byte[] cmd_apdu = apdu.getBuffer();
if (cmd_apdu[ISO7816.OFFSET_P1] != 0x00)
ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
short offset = (short) (cmd_apdu[ISO7816.OFFSET_P2] & 0x00FF);
if (offset >= SIZE_MEMORY)
ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
short lc = (short)(cmd_apdu[ISO7816.OFFSET_LC] & 0x00FF);
if ((offset + lc) > SIZE_MEMORY)
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
if (lc == 0x00)
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
getAPDUBody(apdu);
Util.arrayCopy(cmd_apdu, (short)((ISO7816.OFFSET_CDATA) & 0x00FF),
memory, offset, lc);
ISOException.throwIt(ISO7816.SW_NO_ERROR);
}

public void getAPDUBody(APDU apdu) {
byte[] buffer = apdu.getBuffer();
short lc = (short)(buffer[ISO7816.OFFSET_LC] & 0x00FF);
if (lc != apdu.setIncomingAndReceive())
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}

private void readUserInfo(APDU apdu) {
byte[] cmd_apdu = apdu.getBuffer();
if (cmd_apdu[ISO7816.OFFSET_P1] != 0x00) ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
short offset = (short) (cmd_apdu[ISO7816.OFFSET_P2] & 0x00FF);
if (offset >= SIZE_MEMORY) ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
short le = (short)(cmd_apdu[ISO7816.OFFSET_LC] & 0x00FF);
if (le == 0x00) le = (short)(SIZE_MEMORY - offset);
if ((offset + le) > SIZE_MEMORY) ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
apdu.setOutgoing();
apdu.setOutgoingLength((short)le);
apdu.sendBytesLong(memory, (short)offset, (short)le);

}

private void writeitUserInfo(APDU apdu) {
byte[] cmd_apdu = apdu.getBuffer();
if (cmd_apdu[ISO7816.OFFSET_P1] != 0)
ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
short offset = (short) (cmd_apdu[ISO7816.OFFSET_P2] & 0x00FF);
if (offset >= SIZE_MEMORY)
ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
short lc = (short)(cmd_apdu[ISO7816.OFFSET_LC] & 0x00FF);
if ((offset + lc) > SIZE_MEMORY)
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
if (lc == 0x00)
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
getAPDUBody(apdu);
Util.arrayCopy(cmd_apdu, (short)((ISO7816.OFFSET_CDATA) & 0x00FF),
memoryy, offset, lc);
ISOException.throwIt(ISO7816.SW_NO_ERROR);
}

private void readitUserInfo(APDU apdu) {
byte[] cmd_apdu = apdu.getBuffer();
if (cmd_apdu[ISO7816.OFFSET_P1] != 0x00) ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
short offset = (short) (cmd_apdu[ISO7816.OFFSET_P2] & 0x00FF);
if (offset >= SIZE_MEMORY) ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
short le = (short)(cmd_apdu[ISO7816.OFFSET_LC] & 0x00FF);
if (le == 0x00) le = (short)(SIZE_MEMORY - offset);
if ((offset + le) > SIZE_MEMORY) ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
apdu.setOutgoing();
apdu.setOutgoingLength((short)le);
apdu.sendBytesLong(memoryy, (short)offset, (short)le);

}
}

我知道错误在第 56 行,但我猜那将来自 Transfer.class 文件(我无法打开它阅读),而不是在源代码中。但是我能想到的唯一未分配的中间值是在读取传入的 APDU header 时的指令案例。

这个错误可能来自哪里?

最佳答案

错误已经清楚地告诉您源文件中包含有问题代码的行。在您的情况下,错误是由带有 if 语句的所有行引起的

if ((offset + lc) > SIZE_MEMORY) 

本例中整数类型的中间值是offset + lc。尽管加号运算符的两个操作数都是短整型,但加号运算符的结果是一个整数。因此,您需要将此值显式转换回 short:

if ((short)(offset + lc) > SIZE_MEMORY) 

还要注意常量 SIZE_MEMORY 应该是 short 类型而不是 byte:

final static short SIZE_MEMORY = (short) 127;

关于java - CAP 转换器失败并显示 'unsupported int type of intermediate value, must cast value to type short or byte',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43309566/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com