Updated on 2026-08-14

This commit is contained in:
Tangem 2020-04-23 15:05:02 +03:00
parent 19e6c34aa7
commit 3f83609c2c
6 changed files with 21 additions and 11 deletions

View file

@ -0,0 +1,14 @@
package com.tangem
import com.tangem.common.extensions.CardType
import java.util.*
/**
* Filter that can be used to limit cards that can be interacted with in TangemSdk.
*
* @property allowedCardTypes Type of cards that are allowed to be interacted with in TangemSdk.
*/
data class CardFilter(
var allowedCardTypes: EnumSet<CardType> = EnumSet.allOf(CardType::class.java)
)

View file

@ -137,7 +137,8 @@ class CardSession(
callback(CompletionResult.Failure(SessionError.WrongCard()))
return@run
}
if (!environment.allowedCards.contains(result.data.getType())) {
val allowedCardTypes = environment.cardFilter.allowedCardTypes
if (!allowedCardTypes.contains(result.data.getType())) {
stopWithError(SessionError.WrongCardType())
callback(CompletionResult.Failure(SessionError.WrongCardType()))
return@run

View file

@ -1,8 +1,5 @@
package com.tangem
import com.tangem.common.extensions.CardType
import java.util.*
class Config(
/**
* Enables or disables Linked Terminal feature.
@ -35,7 +32,7 @@ class Config(
var encryptionMode: EncryptionMode = EncryptionMode.NONE,
/**
* Type of cards that are allowed to be interacted with in TangemSdk.
* Filter that can be used to limit cards that can be interacted with in TangemSdk.
*/
var allowedCards: EnumSet<CardType> = EnumSet.allOf(CardType::class.java)
val cardFilter: CardFilter = CardFilter()
)

View file

@ -2,10 +2,8 @@ package com.tangem
import com.tangem.commands.Card
import com.tangem.commands.EllipticCurve
import com.tangem.common.extensions.CardType
import com.tangem.common.extensions.calculateSha256
import com.tangem.crypto.CryptoUtils.generatePublicKey
import java.util.*
/**
@ -23,7 +21,7 @@ data class SessionEnvironment(
var encryptionMode: EncryptionMode = EncryptionMode.NONE,
var encryptionKey: ByteArray? = null,
val cvc: ByteArray? = null,
var allowedCards: EnumSet<CardType>
var cardFilter: CardFilter
) {
fun setPin1(pin1: String) {

View file

@ -368,7 +368,7 @@ class TangemSdk(
val terminalKeys = if (config.linkedTerminal) terminalKeysService?.getKeys() else null
return SessionEnvironment(
terminalKeys = terminalKeys,
allowedCards = config.allowedCards
cardFilter = config.cardFilter
)
}

View file

@ -45,7 +45,7 @@ class ActionViewModel(private val itemsManager: ItemsManager) : ViewModel(), Lif
fun setCardManager(tangemSdk: TangemSdk) {
this.tangemSdk = tangemSdk
this.tangemSdk.config.allowedCards = EnumSet.of(CardType.Sdk)
this.tangemSdk.config.cardFilter.allowedCardTypes = EnumSet.of(CardType.Sdk)
}
@Deprecated("Events must be send directly from the Widget")