【问题标题】:Re writing Funcition with APDU & Boolean用 APDU & Boolean 重写函数
【发布时间】:2021-06-23 14:20:16
【问题描述】:

我需要帮助

如果 while 被执行或不执行,我需要这个函数返回一个布尔值。

你能帮帮我吗?

【问题讨论】:

  • 重绘?那有什么意思?为什么需要重绘方法?
  • 感谢您的评论。我的问题不是很清楚,@Maarten Bodewes,我重新写了我的问题
  • 在上面的代码中,while 总是被执行。有趣的是,我认为这个例子来自from the official API description of APDU。这意味着应该重写。我也许可以为此做点什么。

标签: java function javacard apdu iso-7816-4


【解决方案1】:

让我们从 API 重写那个 APDU 示例,因为它显然被破坏了。它会在不需要时向receiveBytes 生成单独的请求。

public boolean receiveIncomingFNEL(APDU apdu) {
    byte[] buf = apdu.getBuffer();

    short bytesRead = apdu.setIncomingAndReceive();
    // NOTE: we must always call setIncomingAndReceive() first
    short offsetCdata = apdu.getOffsetCdata();
    short bytesLeft = apdu.getIncomingLength() - bytesRead;
    boolean receiveBytesRequired = true;
    while (true) {
        // --- do something with the bytes in buf, offsetCdata and bytesRead here
        if (bytesLeft <= 0) {
             receiveBytesRequired = false;
             break;
        }
        bytesRead = apdu.receiveBytes(offsetCdata);
        bytesLeft -= bytesRead;
    }
    // --- do other stuff
    return receiveBytesRequired;
}

while() 循环中的 if 和 break 语句有点奇怪,但这是我能想到的唯一方法,在 APDU 缓冲区中有一个地方处理数据,而@987654326 有一个地方处理数据@ 叫做。这是因为setIncomingAndReceive() 在调用中包含receiveBytes()(欢迎创建普通while 循环的想法)。

【讨论】:

  • 你能试驾一下吗?我这里没有准备好智能卡环境。
  • 它工作正常!非常感谢马丁
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-03
  • 1970-01-01
  • 2019-10-18
相关资源
最近更新 更多