-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
156 additions
and
101 deletions.
There are no files selected for viewing
20 changes: 13 additions & 7 deletions
20
...enid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/crypto/Crypto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,39 @@ | ||
package com.sphereon.oid.fed.client.crypto | ||
|
||
import com.sphereon.oid.fed.client.types.ICallbackService | ||
|
||
import com.sphereon.oid.fed.openapi.models.Jwk | ||
|
||
interface ICryptoService { | ||
suspend fun verify( | ||
jwt: String, | ||
key: Jwk, | ||
): Boolean | ||
} | ||
|
||
interface ICryptoCallbackService : ICallbackService<ICryptoService>, ICryptoService | ||
|
||
expect fun cryptoService(): ICryptoCallbackService | ||
|
||
class DefaultPlatformCallback : ICryptoService { | ||
override suspend fun verify(jwt: String): Boolean { | ||
return verify(jwt) | ||
override suspend fun verify(jwt: String, key: Jwk): Boolean { | ||
return verifyImpl(jwt, key) | ||
} | ||
} | ||
|
||
object CryptoServiceObject : ICryptoCallbackService { | ||
private lateinit var platformCallback: ICryptoService | ||
|
||
override suspend fun verify(jwt: String): Boolean { | ||
return this.platformCallback.verify(jwt) | ||
override suspend fun verify(jwt: String, key: Jwk): Boolean { | ||
if (!::platformCallback.isInitialized) { | ||
throw IllegalStateException("CryptoServiceObject not initialized") | ||
} | ||
return platformCallback.verify(jwt, key) | ||
} | ||
|
||
override fun register(platformCallback: ICryptoService?): ICryptoCallbackService { | ||
this.platformCallback = platformCallback ?: DefaultPlatformCallback() | ||
return this | ||
} | ||
} | ||
|
||
expect fun cryptoService(): ICryptoCallbackService | ||
|
||
expect suspend fun verifyImpl(jwt: String, key: Jwk): Boolean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 3 additions & 10 deletions
13
...ent/src/jsTest/kotlin/com/sphereon/oid/fed/client/crypto/CryptoPlatformTestCallback.js.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.