diff --git a/tangem-core/src/main/java/com/tangem/commands/ReadUserDataCommand.kt b/tangem-core/src/main/java/com/tangem/commands/ReadUserDataCommand.kt index a321876aee..1bdd871b8f 100644 --- a/tangem-core/src/main/java/com/tangem/commands/ReadUserDataCommand.kt +++ b/tangem-core/src/main/java/com/tangem/commands/ReadUserDataCommand.kt @@ -63,12 +63,11 @@ class ReadUserDataResponse( class ReadUserDataCommand: CommandSerializer() { override fun serialize(cardEnvironment: CardEnvironment): CommandApdu { - val serializedTlv = TlvBuilder().apply { - append(TlvTag.CardId, cardEnvironment.cardId) - append(TlvTag.Pin, cardEnvironment.pin1) - }.serialize() + val builder = TlvBuilder() + builder.append(TlvTag.CardId, cardEnvironment.cardId) + builder.append(TlvTag.Pin, cardEnvironment.pin1) - return CommandApdu(Instruction.ReadUserData, serializedTlv) + return CommandApdu(Instruction.ReadUserData, builder.serialize()) } override fun deserialize(cardEnvironment: CardEnvironment, responseApdu: ResponseApdu): ReadUserDataResponse? { diff --git a/tangem-core/src/main/java/com/tangem/commands/WriteUserDataCommand.kt b/tangem-core/src/main/java/com/tangem/commands/WriteUserDataCommand.kt index 689e274dea..d512c4ded7 100644 --- a/tangem-core/src/main/java/com/tangem/commands/WriteUserDataCommand.kt +++ b/tangem-core/src/main/java/com/tangem/commands/WriteUserDataCommand.kt @@ -32,25 +32,22 @@ class WriteUserDataResponse( * Writing of User_Counter and User_Data protected only by PIN1. * User_ProtectedCounter and User_ProtectedData additionaly need PIN2 to confirmation. */ -class WriteUserDataCommand( - private val userData: ByteArray? = null, - private val userProtectedData: ByteArray? = null, +class WriteUserDataCommand(private val userData: ByteArray? = null, private val userProtectedData: ByteArray? = null, private val userCounter: Int? = null, - private val userProtectedCounter: Int? = null -): CommandSerializer() { + private val userProtectedCounter: Int? = null): CommandSerializer() { override fun serialize(cardEnvironment: CardEnvironment): CommandApdu { - val serializedTlv = TlvBuilder().apply { - append(TlvTag.CardId, cardEnvironment.cardId) - append(TlvTag.Pin, cardEnvironment.pin1) - append(TlvTag.UserData, userData) - append(TlvTag.UserCounter, userCounter) - append(TlvTag.UserProtectedData, userProtectedData) - append(TlvTag.UserProtectedCounter, userProtectedCounter) - if (userProtectedCounter != null || userProtectedData != null) - append(TlvTag.Pin2, cardEnvironment.pin2) - }.serialize() - return CommandApdu(Instruction.WriteUserData, serializedTlv) + val builder = TlvBuilder() + builder.append(TlvTag.CardId, cardEnvironment.cardId) + builder.append(TlvTag.Pin, cardEnvironment.pin1) + builder.append(TlvTag.UserData, userData) + builder.append(TlvTag.UserCounter, userCounter) + builder.append(TlvTag.UserProtectedData, userProtectedData) + builder.append(TlvTag.UserProtectedCounter, userProtectedCounter) + if (userProtectedCounter != null || userProtectedData != null) + builder.append(TlvTag.Pin2, cardEnvironment.pin2) + + return CommandApdu(Instruction.WriteUserData, builder.serialize()) } override fun deserialize(cardEnvironment: CardEnvironment, responseApdu: ResponseApdu): WriteUserDataResponse? {