From 9580b977479ab8eedeabe9d219251d7533d7dc9c Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 15 Apr 2020 14:38:55 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../java/com/tangem/commands/ReadCommand.kt | 110 ++++++++---------- .../personalization/PersonalizeCommand.kt | 4 +- .../personalization/entities/CardConfig.kt | 4 +- .../java/com/tangem/common/tlv/TlvDecoder.kt | 4 +- .../java/com/tangem/common/tlv/TlvEncoder.kt | 4 +- .../main/java/com/tangem/tasks/ScanTask.kt | 2 +- .../com/tangem/common/tlv/TlvDecoderTest.kt | 24 ++-- .../tangemtest/extensions/CardConfig.kt | 40 ++++--- .../domain/responses/ResponseJsonConverter.kt | 6 +- .../PersonalizationConfigToCardConfig.kt | 44 ++++--- .../responses/converter/CardConverter.kt | 2 +- 11 files changed, 127 insertions(+), 117 deletions(-) diff --git a/tangem-core/src/main/java/com/tangem/commands/ReadCommand.kt b/tangem-core/src/main/java/com/tangem/commands/ReadCommand.kt index 09c188072d..37caa1f0a5 100644 --- a/tangem-core/src/main/java/com/tangem/commands/ReadCommand.kt +++ b/tangem-core/src/main/java/com/tangem/commands/ReadCommand.kt @@ -14,67 +14,50 @@ import java.util.* /** * Determines which type of data is required for signing. */ -data class SigningMethod(val rawValue: Int) { +data class SigningMethodMask(val rawValue: Int) { - fun contains(value: Int): Boolean { + fun contains(signingMethod: SigningMethod): Boolean { return if (rawValue and 0x80 == 0) { - value == rawValue + signingMethod.code == rawValue } else { - rawValue and (0x01 shl value) != 0 + rawValue and (0x01 shl signingMethod.code) != 0 } } +} - companion object { - const val signHash = 0 - const val signRaw = 1 - const val signHashValidatedByIssuer = 2 - const val signRawValidatedByIssuer = 3 - const val signHashValidatedByIssuerAndWriteIssuerData = 4 - const val signRawValidatedByIssuerAndWriteIssuerData = 5 - const val signPos = 6 +enum class SigningMethod(val code: Int) { + SIGN_HASH(0), + SIGN_RAW(1), + SIGN_HASH_VALIDATE_BY_ISSUER(2), + SIGN_RAW_VALIDATE_BY_ISSUER(3), + SIGN_HASH_VALIDATE_BY_ISSUER_WRITE_ISSUER_DATA(4), + SIGN_RAW_VALIDATE_BY_ISSUER_WRITE_ISSUER_DATA(5), + SIGN_POS(6) +} - fun build( - signHash: Boolean = false, - signRaw: Boolean = false, - signHashValidatedByIssuer: Boolean = false, - signRawValidatedByIssuer: Boolean = false, - signHashValidatedByIssuerAndWriteIssuerData: Boolean = false, - signRawValidatedByIssuerAndWriteIssuerData: Boolean = false, - signPos: Boolean = false +class SigningMethodMaskBuilder() { - ): SigningMethod { - fun Boolean.toInt() = if (this) 1 else 0 + private val signingMethods = mutableSetOf() - val signingMethodsCount = 0 + - signHash.toInt() + - signRaw.toInt() + - signHashValidatedByIssuer.toInt() + - signRawValidatedByIssuer.toInt() + - signHashValidatedByIssuerAndWriteIssuerData.toInt() + - signRawValidatedByIssuerAndWriteIssuerData.toInt() + - signPos.toInt() + fun add(signingMethod: SigningMethod) { + signingMethods.add(signingMethod) + } - var signingMethod: Int = 0 - if (signingMethodsCount == 1) { - if (signHash) signingMethod += SigningMethod.signHash - if (signRaw) signingMethod += SigningMethod.signRaw - if (signHashValidatedByIssuer) signingMethod += SigningMethod.signHashValidatedByIssuer - if (signRawValidatedByIssuer) signingMethod += SigningMethod.signRawValidatedByIssuer - if (signHashValidatedByIssuerAndWriteIssuerData) signingMethod += SigningMethod.signHashValidatedByIssuerAndWriteIssuerData - if (signRawValidatedByIssuerAndWriteIssuerData) signingMethod += SigningMethod.signRawValidatedByIssuerAndWriteIssuerData - if (signPos) signingMethod += SigningMethod.signPos - } else if (signingMethodsCount > 1) { - signingMethod = 0x80 - if (signHash) signingMethod += 0x01 - if (signRaw) signingMethod += 0x01 shl SigningMethod.signRaw - if (signHashValidatedByIssuer) signingMethod += 0x01 shl SigningMethod.signHashValidatedByIssuer - if (signRawValidatedByIssuer) signingMethod += 0x01 shl SigningMethod.signRawValidatedByIssuer - if (signHashValidatedByIssuerAndWriteIssuerData) signingMethod += 0x01 shl SigningMethod.signHashValidatedByIssuerAndWriteIssuerData - if (signRawValidatedByIssuerAndWriteIssuerData) signingMethod += 0x01 shl SigningMethod.signRawValidatedByIssuerAndWriteIssuerData - if (signPos) signingMethod += 0x01 shl SigningMethod.signPos + fun build(): SigningMethodMask { + val rawValue: Int = when { + signingMethods.count() == 0 -> { + 0 + } + signingMethods.count() == 1 -> { + signingMethods.iterator().next().code + } + else -> { + signingMethods.fold( + 0x80, { acc, singingMethod -> acc + (0x01 shl singingMethod.code) } + ) } - return SigningMethod(signingMethod) } + return SigningMethodMask(rawValue) } } @@ -113,22 +96,23 @@ enum class CardStatus(val code: Int) { */ data class ProductMask(val rawValue: Int) { - fun contains(value: Int): Boolean = (rawValue and value) != 0 + fun contains(product: Product): Boolean = (rawValue and product.code) != 0 - companion object { - const val note = 0x01 - const val tag = 0x02 - const val idCard = 0x04 - const val idIssuer = 0x08 - } +} + +enum class Product(val code: Int) { + NOTE(0x01), + TAG(0x02), + ID_CARD(0x04), + ID_ISSUER(0x08) } class ProductMaskBuilder() { private var productMaskValue = 0 - fun add(productCode: Int) { - productMaskValue = productMaskValue or productCode + fun add(product: Product) { + productMaskValue = productMaskValue or product.code } fun build() = ProductMask(productMaskValue) @@ -299,7 +283,7 @@ class Card( /** * Defines what data should be submitted to SIGN command. */ - val signingMethod: SigningMethod?, + val signingMethods: SigningMethodMask?, /** * Delay in seconds before COS executes commands protected by PIN2. @@ -343,21 +327,21 @@ class Card( val activationSeed: ByteArray?, /** - * Returned only if [SigningMethod.SignPos] enabling POS transactions is supported by card. + * Returned only if [SigningMethod.SIGN_POS] enabling POS transactions is supported by card. */ val paymentFlowVersion: ByteArray?, /** * This value can be initialized by terminal and will be increased by COS on execution of every [SignCommand]. * For example, this field can store blockchain “nonce” for quick one-touch transaction on POS terminals. - * Returned only if [SigningMethod.SignPos] enabling POS transactions is supported by card. + * Returned only if [SigningMethod.SIGN_POS] enabling POS transactions is supported by card. */ val userCounter: Int?, /** * This value can be initialized by App (with PIN2 confirmation) and will be increased by COS * with the execution of each [SignCommand]. For example, this field can store blockchain “nonce” - * for a quick one-touch transaction on POS terminals. Returned only if [SigningMethod.SignPos]. + * for a quick one-touch transaction on POS terminals. Returned only if [SigningMethod.SIGN_POS]. */ val userProtectedCounter: Int?, @@ -415,7 +399,7 @@ class ReadCommand : Command() { issuerPublicKey = decoder.decodeOptional(TlvTag.IssuerDataPublicKey), curve = decoder.decodeOptional(TlvTag.CurveId), maxSignatures = decoder.decodeOptional(TlvTag.MaxSignatures), - signingMethod = decoder.decodeOptional(TlvTag.SigningMethod), + signingMethods = decoder.decodeOptional(TlvTag.SigningMethod), pauseBeforePin2 = decoder.decodeOptional(TlvTag.PauseBeforePin2), walletPublicKey = decoder.decodeOptional(TlvTag.WalletPublicKey), walletRemainingSignatures = decoder.decodeOptional(TlvTag.RemainingSignatures), diff --git a/tangem-core/src/main/java/com/tangem/commands/personalization/PersonalizeCommand.kt b/tangem-core/src/main/java/com/tangem/commands/personalization/PersonalizeCommand.kt index 24a118322a..e4fe1a8b15 100644 --- a/tangem-core/src/main/java/com/tangem/commands/personalization/PersonalizeCommand.kt +++ b/tangem-core/src/main/java/com/tangem/commands/personalization/PersonalizeCommand.kt @@ -60,7 +60,7 @@ class PersonalizeCommand( issuerPublicKey = decoder.decodeOptional(TlvTag.IssuerDataPublicKey), curve = decoder.decodeOptional(TlvTag.CurveId), maxSignatures = decoder.decodeOptional(TlvTag.MaxSignatures), - signingMethod = decoder.decodeOptional(TlvTag.SigningMethod), + signingMethods = decoder.decodeOptional(TlvTag.SigningMethod), pauseBeforePin2 = decoder.decodeOptional(TlvTag.PauseBeforePin2), walletPublicKey = decoder.decodeOptional(TlvTag.WalletPublicKey), walletRemainingSignatures = decoder.decodeOptional(TlvTag.RemainingSignatures), @@ -105,7 +105,7 @@ class PersonalizeCommand( tlvBuilder.append(TlvTag.CardId, cardId) tlvBuilder.append(TlvTag.CurveId, config.curveID) tlvBuilder.append(TlvTag.MaxSignatures, config.maxSignatures) - tlvBuilder.append(TlvTag.SigningMethod, config.signingMethod) + tlvBuilder.append(TlvTag.SigningMethod, config.signingMethods) tlvBuilder.append(TlvTag.SettingsMask, config.createSettingsMask()) tlvBuilder.append(TlvTag.PauseBeforePin2, config.pauseBeforePin2 / 10) tlvBuilder.append(TlvTag.Cvc, config.cvc.toByteArray()) diff --git a/tangem-core/src/main/java/com/tangem/commands/personalization/entities/CardConfig.kt b/tangem-core/src/main/java/com/tangem/commands/personalization/entities/CardConfig.kt index bc1a082237..2cfd173be1 100644 --- a/tangem-core/src/main/java/com/tangem/commands/personalization/entities/CardConfig.kt +++ b/tangem-core/src/main/java/com/tangem/commands/personalization/entities/CardConfig.kt @@ -2,7 +2,7 @@ package com.tangem.commands.personalization.entities import com.tangem.commands.CardData import com.tangem.commands.EllipticCurve -import com.tangem.commands.SigningMethod +import com.tangem.commands.SigningMethodMask data class NdefRecord( val type: Type, @@ -33,7 +33,7 @@ data class CardConfig( val pauseBeforePin2: Int, val smartSecurityDelay: Boolean, val curveID: EllipticCurve, - val signingMethod: SigningMethod, + val signingMethods: SigningMethodMask, val maxSignatures: Int, val isReusable: Boolean, val allowSwapPin: Boolean, diff --git a/tangem-core/src/main/java/com/tangem/common/tlv/TlvDecoder.kt b/tangem-core/src/main/java/com/tangem/common/tlv/TlvDecoder.kt index 48c14edec4..4954c38c46 100644 --- a/tangem-core/src/main/java/com/tangem/common/tlv/TlvDecoder.kt +++ b/tangem-core/src/main/java/com/tangem/common/tlv/TlvDecoder.kt @@ -122,9 +122,9 @@ class TlvDecoder(val tlvList: List) { } } TlvValueType.SigningMethod -> { - typeCheck(tag) + typeCheck(tag) try { - SigningMethod(tlvValue.toInt()) as T + SigningMethodMask(tlvValue.toInt()) as T } catch (exception: Exception) { logException(tag, tlvValue.toInt().toString(), exception) throw SessionError.DecodingFailed() diff --git a/tangem-core/src/main/java/com/tangem/common/tlv/TlvEncoder.kt b/tangem-core/src/main/java/com/tangem/common/tlv/TlvEncoder.kt index 1855badcab..057b0807e8 100644 --- a/tangem-core/src/main/java/com/tangem/common/tlv/TlvEncoder.kt +++ b/tangem-core/src/main/java/com/tangem/common/tlv/TlvEncoder.kt @@ -87,8 +87,8 @@ class TlvEncoder { (value as CardStatus).code.toByteArray() } TlvValueType.SigningMethod -> { - typeCheck(tag) - byteArrayOf((value as SigningMethod).rawValue.toByte()) + typeCheck(tag) + byteArrayOf((value as SigningMethodMask).rawValue.toByte()) } TlvValueType.IssuerDataMode -> { typeCheck(tag) diff --git a/tangem-core/src/main/java/com/tangem/tasks/ScanTask.kt b/tangem-core/src/main/java/com/tangem/tasks/ScanTask.kt index 207cb6f705..3ce71ce30e 100644 --- a/tangem-core/src/main/java/com/tangem/tasks/ScanTask.kt +++ b/tangem-core/src/main/java/com/tangem/tasks/ScanTask.kt @@ -20,7 +20,7 @@ internal class ScanTask : CardSessionRunnable { if (card == null) { callback(CompletionResult.Failure(SessionError.MissingPreflightRead())) - } else if (card.cardData?.productMask?.contains(ProductMask.tag) != false) { + } else if (card.cardData?.productMask?.contains(Product.TAG) != false) { callback(CompletionResult.Success(card)) } else if (card.status != CardStatus.Loaded) { diff --git a/tangem-core/src/test/java/com/tangem/common/tlv/TlvDecoderTest.kt b/tangem-core/src/test/java/com/tangem/common/tlv/TlvDecoderTest.kt index f9915fc7b8..cbb9780c47 100644 --- a/tangem-core/src/test/java/com/tangem/common/tlv/TlvDecoderTest.kt +++ b/tangem-core/src/test/java/com/tangem/common/tlv/TlvDecoderTest.kt @@ -82,8 +82,8 @@ class TlvDecoderTest { @Test fun `map SigningMethods single value returns correct value`() { - val signingMethods: SigningMethod = tlvMapper.decode(TlvTag.SigningMethod) - assertThat(signingMethods.contains(SigningMethod.signHash)) + val signingMethods: SigningMethodMask = tlvMapper.decode(TlvTag.SigningMethod) + assertThat(signingMethods.contains(SigningMethod.SIGN_HASH)) .isTrue() } @@ -91,20 +91,20 @@ class TlvDecoderTest { fun `map SigningMethods set of methods returns correct value`() { val localMapper = TlvDecoder(Tlv.deserialize("070195".hexToBytes())!!) - val signingMethod: SigningMethod = localMapper.decode(TlvTag.SigningMethod) - assertThat(signingMethod.contains(SigningMethod.signHash)) + val signingMethods: SigningMethodMask = localMapper.decode(TlvTag.SigningMethod) + assertThat(signingMethods.contains(SigningMethod.SIGN_HASH)) .isTrue() - assertThat(signingMethod.contains(SigningMethod.signHashValidatedByIssuer)) + assertThat(signingMethods.contains(SigningMethod.SIGN_HASH_VALIDATE_BY_ISSUER)) .isTrue() - assertThat(signingMethod.contains(SigningMethod.signHashValidatedByIssuerAndWriteIssuerData)) + assertThat(signingMethods.contains(SigningMethod.SIGN_HASH_VALIDATE_BY_ISSUER_WRITE_ISSUER_DATA)) .isTrue() - assertThat(signingMethod.contains(SigningMethod.signRaw)) + assertThat(signingMethods.contains(SigningMethod.SIGN_RAW)) .isFalse() - assertThat(signingMethod.contains(SigningMethod.signRawValidatedByIssuer)) + assertThat(signingMethods.contains(SigningMethod.SIGN_RAW_VALIDATE_BY_ISSUER)) .isFalse() - assertThat(signingMethod.contains(SigningMethod.signRawValidatedByIssuerAndWriteIssuerData)) + assertThat(signingMethods.contains(SigningMethod.SIGN_RAW_VALIDATE_BY_ISSUER_WRITE_ISSUER_DATA)) .isFalse() - assertThat(signingMethod.contains(SigningMethod.signPos)) + assertThat(signingMethods.contains(SigningMethod.SIGN_POS)) .isFalse() } @@ -119,7 +119,7 @@ class TlvDecoderTest { fun `map ProductMask with raw value 5 returns correct value`() { val localMapper = TlvDecoder(listOf(Tlv(TlvTag.ProductMask, byteArrayOf(5)))) val productMask: ProductMask = localMapper.decode(TlvTag.ProductMask) - assertThat(productMask.contains(ProductMask.note) && productMask.contains(ProductMask.idCard)) + assertThat(productMask.contains(Product.NOTE) && productMask.contains(Product.ID_CARD)) .isTrue() } @@ -127,7 +127,7 @@ class TlvDecoderTest { fun `map ProductMask with raw value 1 returns correct value`() { val localMapper = TlvDecoder(listOf(Tlv(TlvTag.ProductMask, byteArrayOf(1)))) val productMask: ProductMask = localMapper.decode(TlvTag.ProductMask) - assertThat(productMask.contains(ProductMask.note)) + assertThat(productMask.contains(Product.NOTE)) .isTrue() } diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/extensions/CardConfig.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/extensions/CardConfig.kt index c8f68bec9c..134f110c7d 100644 --- a/tangem-demo/src/main/java/com/tangem/tangemtest/extensions/CardConfig.kt +++ b/tangem-demo/src/main/java/com/tangem/tangemtest/extensions/CardConfig.kt @@ -11,24 +11,38 @@ fun CardConfig.Companion.create(application: Application): CardConfig { val preferences = application.getSharedPreferences("prefs", Context.MODE_PRIVATE) - val signingMethod = SigningMethod.build( - signHash = preferences.getBoolean("personalization_SigningMethod_0", false), - signRaw = preferences.getBoolean("personalization_SigningMethod_1", false), - signHashValidatedByIssuer = preferences.getBoolean("personalization_SigningMethod_2", false), - signRawValidatedByIssuer = preferences.getBoolean("personalization_SigningMethod_3", false), - signHashValidatedByIssuerAndWriteIssuerData = preferences.getBoolean("personalization_SigningMethod_4", false), - signRawValidatedByIssuerAndWriteIssuerData = preferences.getBoolean("personalization_SigningMethod_5", false), - signPos = preferences.getBoolean("personalization_SigningMethod_6", false) - ) + val signingMethodMaskBuilder = SigningMethodMaskBuilder() + if (preferences.getBoolean("personalization_SigningMethod_0", false)) { + signingMethodMaskBuilder.add(SigningMethod.SIGN_HASH) + } + if (preferences.getBoolean("personalization_SigningMethod_1", false)) { + signingMethodMaskBuilder.add(SigningMethod.SIGN_RAW) + } + if (preferences.getBoolean("personalization_SigningMethod_2", false)) { + signingMethodMaskBuilder.add(SigningMethod.SIGN_HASH_VALIDATE_BY_ISSUER) + } + if (preferences.getBoolean("personalization_SigningMethod_3", false)) { + signingMethodMaskBuilder.add(SigningMethod.SIGN_RAW_VALIDATE_BY_ISSUER) + } + if (preferences.getBoolean("personalization_SigningMethod_4", false)) { + signingMethodMaskBuilder.add(SigningMethod.SIGN_HASH_VALIDATE_BY_ISSUER_WRITE_ISSUER_DATA) + } + if (preferences.getBoolean("personalization_SigningMethod_5", false)) { + signingMethodMaskBuilder.add(SigningMethod.SIGN_RAW_VALIDATE_BY_ISSUER_WRITE_ISSUER_DATA) + } + if (preferences.getBoolean("personalization_SigningMethod_6", false)) { + signingMethodMaskBuilder.add(SigningMethod.SIGN_HASH) + } + val signingMethod = signingMethodMaskBuilder.build() val isNote = preferences.getBoolean("personalization_ProductMask_IsNote", true) val isTag = preferences.getBoolean("personalization_ProductMask_IsTag", false) val isIdCard = preferences.getBoolean("personalization_ProductMask_IsIDCard", false) val productMaskBuilder = ProductMaskBuilder() - if (isNote) productMaskBuilder.add(ProductMask.note) - if (isTag) productMaskBuilder.add(ProductMask.tag) - if (isIdCard) productMaskBuilder.add(ProductMask.idCard) + if (isNote) productMaskBuilder.add(Product.NOTE) + if (isTag) productMaskBuilder.add(Product.TAG) + if (isIdCard) productMaskBuilder.add(Product.ID_CARD) val productMask = productMaskBuilder.build() var tokenSymbol: String? = null @@ -80,7 +94,7 @@ fun CardConfig.Companion.create(application: Application): CardConfig { cardData = cardData, curveID = EllipticCurve.byName(preferences.getString("personalization_CurveId", "secp256k1")!!) ?: EllipticCurve.Secp256k1, - signingMethod = signingMethod, + signingMethods = signingMethod, createWallet = preferences.getBoolean("personalization_CreateWallet", true), maxSignatures = preferences.getString("personalization_MaxSignatures", "1000")!!.toInt(), isReusable = preferences.getBoolean("personalization_SettingsMask_IsReusable", true), diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/ucase/domain/responses/ResponseJsonConverter.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/ucase/domain/responses/ResponseJsonConverter.kt index d54bc08a5d..444f2bd35a 100644 --- a/tangem-demo/src/main/java/com/tangem/tangemtest/ucase/domain/responses/ResponseJsonConverter.kt +++ b/tangem-demo/src/main/java/com/tangem/tangemtest/ucase/domain/responses/ResponseJsonConverter.kt @@ -16,7 +16,7 @@ class ResponseJsonConverter { private fun init(): Gson { val builder = GsonBuilder().apply { registerTypeAdapter(ByteArray::class.java, ByteTypeAdapter()) - registerTypeAdapter(SigningMethod::class.java, SigningMethodTypeAdapter()) + registerTypeAdapter(SigningMethodMask::class.java, SigningMethodTypeAdapter()) registerTypeAdapter(SettingsMask::class.java, SettingsMaskTypeAdapter()) registerTypeAdapter(ProductMask::class.java, ProductMaskTypeAdapter()) registerTypeAdapter(Date::class.java, DateTypeAdapter()) @@ -50,8 +50,8 @@ class ProductMaskTypeAdapter : JsonSerializer { } } -class SigningMethodTypeAdapter : JsonSerializer { - override fun serialize(src: SigningMethod, typeOfSrc: Type, context: JsonSerializationContext): JsonElement { +class SigningMethodTypeAdapter : JsonSerializer { + override fun serialize(src: SigningMethodMask, typeOfSrc: Type, context: JsonSerializationContext): JsonElement { return JsonPrimitive(src.rawValue.toString()) } } diff --git a/tangem-demo/src/main/java/com/tangem/tangemtest/ucase/variants/personalize/converter/PersonalizationConfigToCardConfig.kt b/tangem-demo/src/main/java/com/tangem/tangemtest/ucase/variants/personalize/converter/PersonalizationConfigToCardConfig.kt index fa79df96e0..537c21eba5 100644 --- a/tangem-demo/src/main/java/com/tangem/tangemtest/ucase/variants/personalize/converter/PersonalizationConfigToCardConfig.kt +++ b/tangem-demo/src/main/java/com/tangem/tangemtest/ucase/variants/personalize/converter/PersonalizationConfigToCardConfig.kt @@ -1,8 +1,6 @@ package com.tangem.tangemtest.ucase.variants.personalize.converter -import com.tangem.commands.CardData -import com.tangem.commands.EllipticCurve -import com.tangem.commands.ProductMaskBuilder +import com.tangem.commands.* import com.tangem.commands.personalization.entities.CardConfig import com.tangem.commands.personalization.entities.NdefRecord import com.tangem.tangemtest.ucase.variants.personalize.dto.PersonalizationConfig @@ -12,15 +10,29 @@ import java.util.* class PersonalizationConfigToCardConfig : Converter { override fun convert(from: PersonalizationConfig): CardConfig { - val signingMethod = com.tangem.commands.SigningMethod.build( - signHash = from.SigningMethod0, - signRaw = from.SigningMethod1, - signHashValidatedByIssuer = from.SigningMethod2, - signRawValidatedByIssuer = from.SigningMethod3, - signHashValidatedByIssuerAndWriteIssuerData = from.SigningMethod4, - signRawValidatedByIssuerAndWriteIssuerData = from.SigningMethod5, - signPos = from.SigningMethod6 - ) + val signingMethodMaskBuilder = SigningMethodMaskBuilder() + if (from.SigningMethod0) { + signingMethodMaskBuilder.add(SigningMethod.SIGN_HASH) + } + if (from.SigningMethod1) { + signingMethodMaskBuilder.add(SigningMethod.SIGN_RAW) + } + if (from.SigningMethod2) { + signingMethodMaskBuilder.add(SigningMethod.SIGN_HASH_VALIDATE_BY_ISSUER) + } + if (from.SigningMethod3) { + signingMethodMaskBuilder.add(SigningMethod.SIGN_RAW_VALIDATE_BY_ISSUER) + } + if (from.SigningMethod4) { + signingMethodMaskBuilder.add(SigningMethod.SIGN_HASH_VALIDATE_BY_ISSUER_WRITE_ISSUER_DATA) + } + if (from.SigningMethod5) { + signingMethodMaskBuilder.add(SigningMethod.SIGN_RAW_VALIDATE_BY_ISSUER_WRITE_ISSUER_DATA) + } + if (from.SigningMethod6) { + signingMethodMaskBuilder.add(SigningMethod.SIGN_HASH) + } + val signingMethod = signingMethodMaskBuilder.build() val isNote = from.cardData.product_note val isTag = from.cardData.product_tag @@ -28,10 +40,10 @@ class PersonalizationConfigToCardConfig : Converter { group.addItem(TextItem(CardId.issuerPublicKey, from.issuerPublicKey?.toHexString())) group.addItem(TextItem(CardId.curve, stringOf(from.curve))) group.addItem(TextItem(CardId.maxSignatures, stringOf(from.maxSignatures))) - group.addItem(TextItem(CardId.signingMethod, stringOf(from.signingMethod?.rawValue))) + group.addItem(TextItem(CardId.signingMethod, stringOf(from.signingMethods?.rawValue))) group.addItem(TextItem(CardId.pauseBeforePin2, stringOf(from.pauseBeforePin2))) group.addItem(TextItem(CardId.walletPublicKey, stringOf(from.walletPublicKey))) group.addItem(TextItem(CardId.walletRemainingSignatures, stringOf(from.walletRemainingSignatures)))