This commit is contained in:
septs 2025-02-26 12:14:14 +08:00
parent 262ede94bc
commit eca2acba8f
Signed by: septs
SSH key fingerprint: SHA256:ElK0p6DNkbsqYUdJ3I9QHDVf21SQD0c2r+hd7s/r5Co
2 changed files with 10 additions and 8 deletions

View file

@ -19,9 +19,8 @@ fun getESTKmeInfo(iface: ApduInterface): ESTKmeInfo? {
return b.sliceArray(0 until b.size - 2).decodeToString()
}
return try {
iface.openChannel("A06573746B6D65FFFFFFFFFFFF6D6774".decodeHex()) { transmit ->
fun invoke(p1: Byte) =
decode(transmit(byteArrayOf(0x00, 0x00, p1, 0x00, 0x00)))
iface.openChannel("A06573746B6D65FFFFFFFFFFFF6D6774".decodeHex()) {
fun invoke(p1: Byte) = decode(it.transmit(byteArrayOf(0x00, 0x00, p1, 0x00, 0x00)))
ESTKmeInfo(
invoke(0x00), // serial number
invoke(0x01), // bootloader version

View file

@ -17,15 +17,18 @@ interface ApduInterface {
*/
val valid: Boolean
fun <T> openChannel(
aid: ByteArray,
callback: (transmit: (ByteArray) -> ByteArray) -> T
): T {
fun <T> openChannel(aid: ByteArray, callback: (TransmitProvider) -> T): T {
val handle = logicalChannelOpen(aid)
return try {
callback { transmit(handle, it) }
callback(object : TransmitProvider {
override fun transmit(tx: ByteArray) = transmit(handle, tx)
})
} finally {
logicalChannelClose(handle)
}
}
}
interface TransmitProvider {
fun transmit(tx: ByteArray): ByteArray
}