io.github.binaryfoo.decoders.ApplicationFileLocatorDecoder.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of emv-bertlv Show documentation
Show all versions of emv-bertlv Show documentation
Some decoders for the data used in EMV credit card transactions.
package io.github.binaryfoo.decoders
import io.github.binaryfoo.DecodedData
import io.github.binaryfoo.Decoder
import java.util.ArrayList
import kotlin.text.substring
/**
* EMV Book 3 (v4.3) 10.2 Read Application Data
*/
class ApplicationFileLocatorDecoder : Decoder {
override fun decode(input: String, startIndexInBytes: Int, session: DecodeSession): List {
val decoded = ArrayList()
for (offset in 0..input.length-1 step 8) {
val element = input.substring(offset, offset + 8)
val sfi = Integer.parseInt(element.substring(0, 2), 16) shr 3
val firstRecord = Integer.parseInt(element.substring(2, 4))
val lastRecord = Integer.parseInt(element.substring(4, 6))
val decoding = "SFI $sfi " + (if (lastRecord == firstRecord) "record $firstRecord" else "records $firstRecord-$lastRecord")
decoded.add(DecodedData.primitive("", decoding, startIndexInBytes + (offset / 2), startIndexInBytes + (offset / 2) + 4))
}
return decoded
}
override fun validate(input: String?): String? {
return null
}
override fun getMaxLength(): Int {
return 0
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy