io.github.binaryfoo.cmdline.Main.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.cmdline
import io.github.binaryfoo.RootDecoder
import io.github.binaryfoo.TagInfo
import io.github.binaryfoo.decoders.DecodeSession
import java.io.BufferedReader
import java.io.InputStreamReader
/**
* Command line too for parsing a few flavours of chip card data.
*/
class Main {
companion object {
@JvmStatic fun main(args: Array) {
if (args.size < 2) {
printHelp()
System.exit(1)
}
val tag = args[0]
val value = args[1]
val meta = if (args.size > 2) args[2] else "EMV"
val rootDecoder = RootDecoder()
val decodeSession = DecodeSession()
decodeSession.tagMetaData = rootDecoder.getTagMetaData(meta)
val tagInfo = RootDecoder.getTagInfo(tag)
if (tagInfo == null) {
println("Unknown tag $tag")
printHelp();
} else {
if (value == "-") {
val reader = BufferedReader(InputStreamReader(System.`in`))
while (true) {
val line = reader.readLine() ?: break
decodeValue(line, decodeSession, tagInfo)
}
} else {
decodeValue(value, decodeSession, tagInfo)
}
}
}
private fun decodeValue(value: String, decodeSession: DecodeSession, tagInfo: TagInfo) {
val decoded = tagInfo.decoder.decode(value, 0, decodeSession)
DecodedWriter(System.out).write(decoded, "")
}
private fun printHelp() {
System.out.println("Usage Main []")
System.out.println(" is one of")
for (tag in RootDecoder.getSupportedTags()) {
System.out.println(" " + tag.key + ": " + tag.value.shortName)
}
System.out.println(" is the hex string or '-' for standard input")
System.out.println(" is one of " + RootDecoder.getAllTagMeta() + " defaults to EMV")
}
}
}
fun main(args: Array) = Main.main(args)
© 2015 - 2024 Weber Informatics LLC | Privacy Policy