Skip to content

Commit

Permalink
fix: ensure revocation policy decoded bitValue always consists of val…
Browse files Browse the repository at this point in the history
…id binary characters (0,1)
  • Loading branch information
mikeplotean committed Feb 5, 2025
1 parent 42ba97c commit 86e0e12
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ actual class RevocationPolicy : RevocationPolicyMp() {
val credentialSubject = payload["vc"]!!.jsonObject["credentialSubject"]?.jsonObject!!
val encodedList = credentialSubject["encodedList"]?.jsonPrimitive?.content ?: ""
val bitValue = get(encodedList, statusListIndex)
if (StreamUtils.binToInt(bitValue!!.joinToString("")) == 0) {
// ensure bitValue always consists of valid binary characters (0,1)
require(!bitValue.isNullOrEmpty()) { "Null or empty bit value" }
require(isBinaryValue(bitValue)) { "Invalid bit value" }
if (StreamUtils.binToInt(bitValue.joinToString("")) == 0) {
Result.success(statusListCredentialUrl!!)
} else {
Result.failure(Throwable("Credential has been revoked"))
Expand Down Expand Up @@ -91,4 +94,8 @@ object StreamUtils {
}

fun get(bitstring: String, idx: ULong? = null, bitSize: Int = 1) =
idx?.let { StreamUtils.getBitValue(GZIPInputStream(Base64Utils.decode(bitstring).inputStream()), it, bitSize) }
idx?.let { StreamUtils.getBitValue(GZIPInputStream(Base64Utils.decode(bitstring).inputStream()), it, bitSize) }

fun isBinaryValue(value: List<Char>) = setOf('0', '1').let { valid ->
value.all { it in valid }
}

0 comments on commit 86e0e12

Please sign in to comment.