Skip to content

Commit

Permalink
fix: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmelati committed Oct 19, 2024
1 parent 80941c1 commit 2d638d2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ expect fun cryptoService(): ICryptoCallbackService

expect suspend fun verifyImpl(jwt: String, key: Jwk): Boolean

private fun findKeyInJwks(keys: JsonArray, kid: String): Jwk? {
fun findKeyInJwks(keys: JsonArray, kid: String): Jwk? {
val key = keys.firstOrNull { it.jsonObject["kid"]?.jsonPrimitive?.content?.trim() == kid.trim() }

if (key == null) return null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sphereon.oid.fed.client.trustchain

import com.sphereon.oid.fed.client.crypto.ICryptoCallbackService
import com.sphereon.oid.fed.client.crypto.findKeyInJwks
import com.sphereon.oid.fed.client.fetch.IFetchCallbackService
import com.sphereon.oid.fed.client.helpers.getEntityConfigurationEndpoint
import com.sphereon.oid.fed.client.helpers.getSubordinateStatementEndpoint
Expand All @@ -9,8 +10,6 @@ import com.sphereon.oid.fed.client.mapper.mapEntityStatement
import com.sphereon.oid.fed.openapi.models.EntityConfigurationStatement
import com.sphereon.oid.fed.openapi.models.Jwk
import com.sphereon.oid.fed.openapi.models.SubordinateStatement
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonObject
Expand Down Expand Up @@ -41,14 +40,6 @@ class TrustChain(private val fetchService: IFetchCallbackService, private val cr
}
}

private fun findKeyInJwks(keys: JsonArray, kid: String): Jwk? {
val key = keys.firstOrNull { it.jsonObject["kid"]?.jsonPrimitive?.content == kid }

if (key == null) return null

return Json.decodeFromJsonElement(Jwk.serializer(), key)
}

private suspend fun buildTrustChainRecursive(
entityIdentifier: String,
trustAnchors: Array<String>,
Expand Down

0 comments on commit 2d638d2

Please sign in to comment.