checking omapi logical channel open failed

This commit is contained in:
septs 2025-02-26 16:53:46 +08:00
parent 30279aeac7
commit f12f6ccaa2
Signed by: septs
SSH key fingerprint: SHA256:ElK0p6DNkbsqYUdJ3I9QHDVf21SQD0c2r+hd7s/r5Co

View file

@ -39,7 +39,8 @@ class OmapiApduInterface(
}
override fun logicalChannelOpen(aid: ByteArray): Int {
val channel = session.openLogicalChannel(aid)!!
val channel = session.openLogicalChannel(aid)
check(channel != null) { "Failed to open logical channel (${aid.encodeHex()})" }
val id = index.addAndGet(1)
channels[id] = channel
return id
@ -47,11 +48,9 @@ class OmapiApduInterface(
override fun logicalChannelClose(handle: Int) {
val channel = channels[handle]
check(channel != null) {
"Invalid logical channel handle $handle"
}
check(channel != null) { "Invalid logical channel handle $handle" }
channels.remove(handle)
channel.close()
if (channel.isOpen) channel.close()
}
override fun transmit(handle: Int, tx: ByteArray): ByteArray {