Updated on 2026-08-14

This commit is contained in:
Tangem 2020-04-13 09:24:20 +03:00
parent 3661133163
commit e8ae6ccb2d
5 changed files with 25 additions and 3 deletions

View file

@ -48,6 +48,7 @@ class CardSession(
private val initialMessage: Message? = null
) {
private val tag = this.javaClass.simpleName
/**
* True if some operation is still in progress.
*/
@ -164,7 +165,10 @@ class CardSession(
} else {
error.localizedMessage
}
if (error !is SessionError.UserCancelled) viewDelegate.onError(errorMessage)
if (error !is SessionError.UserCancelled) {
Log.e("tag", "Finishing with error: $errorMessage")
viewDelegate.onError(errorMessage)
}
}
fun send(apdu: CommandApdu, callback: (result: CompletionResult<ResponseApdu>) -> Unit) {
@ -176,6 +180,7 @@ class CardSession(
when (error) {
is SessionError.NeedEncryption -> {
Log.i(tag, "Establishing encryption")
when (environment.encryptionMode) {
EncryptionMode.NONE -> {
environment.encryptionKey = null
@ -186,7 +191,7 @@ class CardSession(
environment.encryptionMode = EncryptionMode.STRONG
}
EncryptionMode.STRONG -> {
Log.e(this::class.simpleName!!, "Encryption doesn't work")
Log.e(tag, "Encryption doesn't work")
callback(CompletionResult.Failure(SessionError.NeedEncryption()))
}
}

View file

@ -38,6 +38,7 @@ abstract class Command<T : CommandResponse> : CardSessionRunnable<T> {
abstract fun deserialize(environment: SessionEnvironment, apdu: ResponseApdu): T
override fun run(session: CardSession, callback: (result: CompletionResult<T>) -> Unit) {
Log.i("Command", "Sending ${this::class.java.simpleName}")
transceive(session, callback)
}

View file

@ -1,6 +1,7 @@
package com.tangem.common.tlv
import com.tangem.Log
import com.tangem.common.extensions.toHexString
import java.io.ByteArrayInputStream
import java.io.IOException
@ -71,6 +72,10 @@ class Tlv {
}
}
override fun toString(): String {
return "${this.tag} ($tagRaw): ${value.toHexString()}"
}
}
fun List<Tlv>.serialize(): ByteArray =

View file

@ -1,5 +1,7 @@
package com.tangem.common.tlv
import com.tangem.Log
class TlvBuilder {
private val tlvs = mutableListOf<Tlv>()
private val encoder = TlvEncoder()
@ -10,6 +12,10 @@ class TlvBuilder {
tlvs.add(encoder.encode(tag, value))
}
fun serialize(): ByteArray = tlvs.serialize()
fun serialize(): ByteArray {
Log.v("TLV",
"List of TLV that are being sent to a card:\n${tlvs.joinToString("\n")}")
return tlvs.serialize()
}
}

View file

@ -18,6 +18,11 @@ import java.util.*
*/
class TlvDecoder(val tlvList: List<Tlv>) {
init {
Log.v("TLV",
"List of TLV received from card:\n${tlvList.joinToString("\n")}")
}
/**
* Finds [Tlv] by its [TlvTag].
* Returns null if [Tlv] is not found, otherwise converts its value to [T].