Updated on 2026-08-14
This commit is contained in:
parent
dbcbc6b558
commit
ea39fd060d
10 changed files with 355 additions and 22 deletions
|
|
@ -33,7 +33,6 @@ class CheckWalletResponse(
|
|||
* @property challenge Random challenge generated by application
|
||||
*/
|
||||
class CheckWalletCommand(
|
||||
private val pin1: String,
|
||||
private val cardId: String,
|
||||
private val challenge: ByteArray
|
||||
) : CommandSerializer<CheckWalletResponse>() {
|
||||
|
|
|
|||
|
|
@ -14,18 +14,24 @@ import java.util.*
|
|||
/**
|
||||
* Determines which type of data is required for signing.
|
||||
*/
|
||||
enum class SigningMethod(val code: Int) {
|
||||
SignHash(0),
|
||||
SignRaw(1),
|
||||
SignHashValidatedByIssuer(2),
|
||||
SignRawValidatedByIssuer(3),
|
||||
SignHashValidatedByIssuerAndWriteIssuerData(4),
|
||||
SignRawValidatedByIssuerAndWriteIssuerData(5),
|
||||
SignPos(6);
|
||||
data class SigningMethod(val rawValue: Int) {
|
||||
|
||||
fun contains(value: Int): Boolean {
|
||||
return if (rawValue and 0x80 == 0) {
|
||||
value == rawValue
|
||||
} else {
|
||||
rawValue and (0x01 shl value) != 0
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val values = values()
|
||||
fun byCode(code: Int): SigningMethod? = values.find { it.code == code }
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -76,6 +82,8 @@ enum class ProductMask(val code: Byte) {
|
|||
*/
|
||||
data class SettingsMask(val rawValue: Int) {
|
||||
|
||||
fun contains(value: Int): Boolean = (rawValue and value) != 0
|
||||
|
||||
companion object {
|
||||
const val isReusable = 0x0001
|
||||
const val useActivation = 0x0002
|
||||
|
|
|
|||
|
|
@ -9,14 +9,9 @@ import kotlin.experimental.and
|
|||
* Extension functions for [ByteArray].
|
||||
*/
|
||||
|
||||
fun ByteArray.toHexString() = joinToString("") { "%02x".format(it) }
|
||||
|
||||
fun ByteArray.toUtf8(): String {
|
||||
val string = String(this)
|
||||
if (this.isNotEmpty() && this.last() == 0.toByte()) return string.dropLast(1)
|
||||
return string
|
||||
}
|
||||
fun ByteArray.toHexString(): String = joinToString("") { "%02x".format(it) }
|
||||
|
||||
fun ByteArray.toUtf8(): String = String(this).removeSuffix("\u0000")
|
||||
|
||||
fun ByteArray.toInt(): Int {
|
||||
return when (this.size) {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class Tlv {
|
|||
|
||||
|
||||
companion object {
|
||||
fun tlvFromBytes(stream: ByteArrayInputStream): Tlv? {
|
||||
private fun tlvFromBytes(stream: ByteArrayInputStream): Tlv? {
|
||||
val code = stream.read()
|
||||
if (code == -1) return null
|
||||
var len = stream.read()
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ class TlvMapper(val tlvList: List<Tlv>) {
|
|||
TlvValueType.SigningMethod -> {
|
||||
if (T::class != SigningMethod::class)
|
||||
throw WrongTypeException("Mapping error. Type for tag: $tag must be ${tag.valueType()}. It is ${T::class}")
|
||||
SigningMethod.byCode(tlvValue.toInt()) as T
|
||||
SigningMethod(tlvValue.toInt()) as T
|
||||
?: throw ConversionException("Unknown Signing Method with code of: ${tlvValue.toInt()}")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ enum class TlvTag(val code: Int) {
|
|||
TlvValueType.Utf8String
|
||||
CurveId -> TlvValueType.EllipticCurve
|
||||
MaxSignatures, PauseBeforePin2, RemainingSignatures,
|
||||
SignedHashes, Health, TokenDecimal, UserCounter -> TlvValueType.IntValue
|
||||
SignedHashes, Health, TokenDecimal, UserCounter, IssuerDataCounter -> TlvValueType.IntValue
|
||||
IsActivated, TerminalIsLinked -> TlvValueType.BoolValue
|
||||
ManufactureDateTime -> TlvValueType.DateTime
|
||||
ProductMask -> TlvValueType.ProductMask
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@ internal class ScanTask : Task<ScanEvent>() {
|
|||
|
||||
val challenge = CryptoUtils.generateRandomBytes(16)
|
||||
val checkWalletCommand = CheckWalletCommand(
|
||||
cardEnvironment.pin1,
|
||||
card.cardId,
|
||||
challenge)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue