-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #690 from walt-id/keymanager-java-wrapper
Make it easier to register key type in KeyManager from Java
- Loading branch information
Showing
3 changed files
with
39 additions
and
4 deletions.
There are no files selected for viewing
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
28 changes: 28 additions & 0 deletions
28
...s/crypto/waltid-crypto/src/jvmMain/kotlin/id/walt/crypto/keys/KeyManagerJavaExtensions.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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package id.walt.crypto.keys | ||
|
||
import kotlin.jvm.internal.Reflection | ||
|
||
object KeyManagerJavaExtensions { | ||
|
||
/** | ||
* Use like this from Java: | ||
* ``` | ||
* KeyManagerJavaExtensions.INSTANCE.register(MyJavaBasedKey.class, "theTypeId", | ||
* keyGenerationRequest -> { | ||
* String backend = keyGenerationRequest.getBackend(); | ||
* KeyType keyType = keyGenerationRequest.getKeyType(); | ||
* | ||
* // Return key here | ||
* return null; | ||
* } | ||
* ); | ||
* ``` | ||
*/ | ||
fun register(javaClass: Class<out Key>, typeId: String, createFunction: (KeyGenerationRequest) -> Key) = | ||
KeyManager.registerByType( | ||
type = Reflection.typeOf(javaClass), | ||
typeId = typeId, | ||
createFunction = createFunction | ||
) | ||
|
||
} |