refactor
This commit is contained in:
parent
262ede94bc
commit
eca2acba8f
2 changed files with 10 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
Loading…
Add table
Reference in a new issue