Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot parse an empty data source #20

Open
IonutNegru87 opened this issue Nov 21, 2022 · 1 comment
Open

Cannot parse an empty data source #20

IonutNegru87 opened this issue Nov 21, 2022 · 1 comment

Comments

@IonutNegru87
Copy link

In the scenario where the data source is empty the library crashes throwing Method java.lang.IndexOutOfBoundsException exception.

Code used to test this:

assertNull(BerTlv.parse("".toByteArray()))

I think this can be easily fixed by this change in the BerTlv.java class:

@JvmStatic
fun parse(data: ByteArray): BerTlv {
      if (data.isNotEmpty()) {
        return parseList(ByteBuffer.wrap(data), true)[0]
    } else {
        null
    }
}
@IonutNegru87
Copy link
Author

Meanwhile I've created an extension function that does the validation before using the static BerTlv.parse() method:

fun String.parseBerTlv(): BerTlv? {
    return if (ISOUtil.isValidHexString(this)) {
        BerTlv.parse(this.decodeHex())
    } else {
        null
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant