Updated on 2026-08-14

This commit is contained in:
Tangem 2019-11-18 10:41:50 +00:00
commit 4c0ef80dd8
7 changed files with 107 additions and 11 deletions

View file

@ -59,7 +59,6 @@ class CommandApdu(
val lc = data.size
val byteStream = ByteArrayOutputStream()
byteStream.write(cla.toInt())
byteStream.write(ins)
@ -73,7 +72,6 @@ class CommandApdu(
}
private fun writeLength(stream: ByteArrayOutputStream, lc: Int) {
stream.write(0)
stream.write(lc shr 8)
stream.write(lc and 0xFF)

View file

@ -9,7 +9,7 @@ import com.tangem.common.tlv.Tlv
* @property sw Status word code, reflecting the status of the response.
* @property statusWord Parsed status word.
*/
class ResponseApdu(val data: ByteArray) {
class ResponseApdu(private val data: ByteArray) {
private val sw1: Int = 0x00FF and data[data.size - 2].toInt()
private val sw2: Int = 0x00FF and data[data.size - 1].toInt()
@ -26,8 +26,7 @@ class ResponseApdu(val data: ByteArray) {
*/
fun getTlvData(encryptionKey: ByteArray? = null): List<Tlv>? {
return when {
data.size < 2 -> null
data.size == 2 -> emptyList()
data.size <= 2 -> null
else -> Tlv.tlvListFromBytes(data.copyOf(data.size - 2))
}
}

View file

@ -1,5 +1,6 @@
package com.tangem.common.tlv
import com.tangem.Log
import java.io.ByteArrayInputStream
import java.io.IOException
@ -52,7 +53,7 @@ class Tlv {
}
fun tlvListFromBytes(mData: ByteArray): List<Tlv> {
fun tlvListFromBytes(mData: ByteArray): List<Tlv>? {
val tlvList = mutableListOf<Tlv>()
val stream = ByteArrayInputStream(mData)
var tlv: Tlv? = null
@ -61,7 +62,8 @@ class Tlv {
tlv = Tlv.tlvFromBytes(stream)
if (tlv != null) tlvList.add(tlv)
} catch (e: IOException) {
throw TlvMapperException("TLVError: " + e.message)
Log.e(this::class.java.simpleName,"TLVError: " + e.message)
return null
}
} while (tlv != null)