Skip to content

Commit

Permalink
Fix #23: Support for Object and Array in disclosures
Browse files Browse the repository at this point in the history
  • Loading branch information
josmilan committed May 9, 2024
1 parent 9d2140e commit d71d63a
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.ewc.eudi_wallet_oidc_android.services.sdjwt

import android.util.Base64
import android.util.Log
import com.ewc.eudi_wallet_oidc_android.models.PresentationDefinition
import com.ewc.eudi_wallet_oidc_android.models.PresentationRequest
import com.ewc.eudi_wallet_oidc_android.services.verification.VerificationService
import com.github.decentraliseddataexchange.presentationexchangesdk.models.MatchedCredential
import com.google.gson.Gson
import com.google.gson.JsonArray
import com.google.gson.JsonElement
Expand Down Expand Up @@ -204,7 +202,17 @@ class SDJWTService : SDJWTServiceInterface {
// Extract key-value pair from the encodedString
val (decodedKey, decodedValue) = extractKeyValue(disclosure)
// Add key-value pair to jsonObject
jsonObject.addProperty(decodedKey, decodedValue)
// Check if decodedValue is an object
if (decodedValue is JsonObject) {
// If it's an object, add it directly
jsonObject.add(decodedKey, decodedValue)
} else if (decodedValue is JsonArray) {
// If it's an object, add it directly
jsonObject.add(decodedKey, decodedValue)
} else {
// Otherwise, add it as a property
jsonObject.addProperty(decodedKey, decodedValue.toString())
}
} catch (e: IllegalArgumentException) {
// Handle invalid base64-encoded strings
}
Expand All @@ -231,10 +239,10 @@ class SDJWTService : SDJWTServiceInterface {
return false
}

private fun extractKeyValue(decodedString: String): Pair<String, String> {
private fun extractKeyValue(decodedString: String): Pair<String, Any> {
val jsonArray = JsonParser.parseString(decodedString).asJsonArray
val key = jsonArray[1].asString
val value = jsonArray[2].asString
val value = jsonArray[2]
return Pair(key, value)
}

Expand Down

0 comments on commit d71d63a

Please sign in to comment.