Skip to content

Commit

Permalink
fix: bitString base64 encoding for revocation status list (#1273)
Browse files Browse the repository at this point in the history
Signed-off-by: Shota Jolbordi <[email protected]>
  • Loading branch information
shotexa authored Jul 29, 2024
1 parent cf3ccbe commit 45e0613
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ class BitString private (val bitSet: util.BitSet, val size: Int) {
def revokedCount(): UIO[Int] = ZIO.succeed(bitSet.stream().count().toInt)

def encoded: IO[EncodingError, String] = {

for {
bitSetByteArray <- ZIO.succeed(bitSet.toByteArray)
bitSetByteArray <- ZIO.succeed(bitSet.toByteArray.map(x => BitString.reverseBits(x).toByte))

/*
This is where the size constructor parameter comes into play (i.e. the initial bitstring size requested by the user).
Interestingly, the underlying 'bitSet.toByteArray()' method only returns the byte array that are 'in use', which means the bytes needed to hold the current bits that are set to true.
Expand Down Expand Up @@ -52,6 +54,15 @@ object BitString {
*/
val MIN_SL2021_SIZE: Int = 131072

private def reverseBits(b: Int): Int = {
var result: Int = 0
for (i <- 0 until 8) {
val bit = (b >> i) & 1
result = (result << 1) | bit
}
result
}

def getInstance(): IO[BitStringError, BitString] = getInstance(MIN_SL2021_SIZE)

def getInstance(size: Int): IO[BitStringError, BitString] = {
Expand All @@ -65,7 +76,7 @@ object BitString {
} yield {
val bais = new ByteArrayInputStream(ba)
val gzipInputStream = new GZIPInputStream(bais)
val byteArray = gzipInputStream.readAllBytes()
val byteArray = gzipInputStream.readAllBytes().map(x => BitString.reverseBits(x).toByte)
BitString(util.BitSet.valueOf(byteArray), byteArray.length * 8)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ object JWTVerificationTest extends ZIOSpecDefault {
| "type" : "EcdsaSecp256k1Signature2019",
| "proofPurpose" : "assertionMethod",
| "verificationMethod" : "data:application/json;base64,eyJAY29udGV4dCI6WyJodHRwczovL3czaWQub3JnL3NlY3VyaXR5L3YxIl0sInR5cGUiOiJFY2RzYVNlY3AyNTZrMVZlcmlmaWNhdGlvbktleTIwMTkiLCJwdWJsaWNLZXlKd2siOnsiY3J2Ijoic2VjcDI1NmsxIiwia2V5X29wcyI6WyJ2ZXJpZnkiXSwia3R5IjoiRUMiLCJ4IjoiQ1hJRmwyUjE4YW1lTEQteWtTT0dLUW9DQlZiRk01b3Vsa2MydklySnRTND0iLCJ5IjoiRDJRWU5pNi1BOXoxbHhwUmpLYm9jS1NUdk5BSXNOVnNsQmpsemVnWXlVQT0ifX0=",
| "created" : "2024-06-06T22:47:27.987035Z",
| "jws" : "eyJiNjQiOmZhbHNlLCJjcml0IjpbImI2NCJdLCJhbGciOiJFUzI1NksifQ..ERDKKRukFs3UZiBdlH-e9r3rS9n05XDaR3yh-7jtmuZhY40b1CTMELHHRRfnfTv6XJ2ROziN4dj_nU_9W8qi5Q"
| "created" : "2024-07-25T22:49:59.091957Z",
| "jws" : "eyJiNjQiOmZhbHNlLCJjcml0IjpbImI2NCJdLCJhbGciOiJFUzI1NksifQ..FJLUBsZhGB1o_G1UwsVaoL-8agvcpoelJtAr2GlNOOqCSOd-WNEj5-FOgv0m0QcdKMokl2TxibJMg3Y-MJq4-A"
| },
| "@context" : [
| "https://www.w3.org/2018/credentials/v1",
Expand All @@ -50,13 +50,13 @@ object JWTVerificationTest extends ZIOSpecDefault {
| "VerifiableCredential",
| "StatusList2021Credential"
| ],
| "id" : "http://localhost:8085/credential-status/575092c2-7eb0-40ae-8f41-3b499f45f3dc",
| "id" : "http://localhost:8085/credential-status/01def9a2-2bcb-4bb3-8a36-6834066431d0",
| "issuer" : "did:prism:462c4811bf61d7de25b3baf86c5d2f0609b4debe53792d297bf612269bf8593a",
| "issuanceDate" : 1717714047,
| "issuanceDate" : 1721947798,
| "credentialSubject" : {
| "type" : "StatusList2021",
| "statusPurpose" : "Revocation",
| "encodedList" : "H4sIAAAAAAAA_-3BMQ0AAAACIGf_0MbwARoAAAAAAAAAAAAAAAAAAADgbbmHB0sAQAAA"
| "encodedList" : "H4sIAAAAAAAA_-3BIQEAAAACIKf6f4UzLEADAAAAAAAAAAAAAAAAAAAAvA3PduITAEAAAA=="
| }
|}
|""".stripMargin
Expand Down Expand Up @@ -130,7 +130,7 @@ object JWTVerificationTest extends ZIOSpecDefault {
statusPurpose = StatusPurpose.Revocation,
`type` = "StatusList2021Entry",
statusListCredential = "http://localhost:8085/credential-status/664382dc-9e6d-4d0c-99d1-85e2c74eb5e9",
statusListIndex = 2
statusListIndex = 3
)

val urlResolver = new UriResolver {
Expand Down

0 comments on commit 45e0613

Please sign in to comment.