Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java implementation issue with Keys abstract class. #327

Open
saujam opened this issue Apr 15, 2024 · 3 comments · Fixed by #360
Open

Java implementation issue with Keys abstract class. #327

saujam opened this issue Apr 15, 2024 · 3 comments · Fixed by #360
Assignees

Comments

@saujam
Copy link

saujam commented Apr 15, 2024

Hi Team,
I am experiencing this issue when extending the Keys class (id.walt.crypto.keys) from waltid-crypto-jvm-0.2.0.jar. The issue occurs only with the following methods since the java de-compiler adds a postfix (verifyRaw-0E7RQCE) with a dash character that Java does not support.
I would appreciate it if you could check and let me know.

  1. public abstract Object verifyRaw_0E7RQCE/* $FF was: verifyRaw-0E7RQCE*/(@NotNull byte[] var1, @nullable byte[] var2, @NotNull Continuation var3);
  2. public abstract Object verifyJws_gIAlu_s/* $FF was: verifyJws-gIAlu-s*/(@NotNull String var1, @NotNull Continuation var2);
@philpotisk
Copy link
Contributor

Hi @saujam as you see in the picture, I could reproduce the issue. Due to the "inline" Result class the suffix is produced, which can not be inherited from Java.
Screenshot_20240417_215723

To solve this issue, I could think of two options:
1.) Change the result type in the Key interface or
2.) Wrap the Result within a subclass for the JVM, as you see in the next screenshot, which at least works in my PoC:

image

I will discuss these options with the team an come back to you.

@kbrgmn
Copy link

kbrgmn commented Apr 25, 2024

Hi @saujam,

if you want to implement a Key in Java instead of Kotlin, you will have to extend from JavaKey instead of Key. There you will not have to handle suspend/coroutines or the kotlin.Result return type.

This is a stub you can utilize:

import id.walt.crypto.keys.JavaKey;
import id.walt.crypto.keys.Key;
import id.walt.crypto.keys.KeyMeta;
import id.walt.crypto.keys.KeyType;
import java.util.Map;
import kotlinx.serialization.json.JsonElement;
import kotlinx.serialization.json.JsonObject;
import org.jetbrains.annotations.NotNull;

public class MyKey extends JavaKey {

    private String _xyz;

    public MyKey(String xyz) {
        this._xyz = xyz;
    }

    @NotNull
    @Override
    public KeyMeta javaGetMeta() {
        return null;
    }

    @NotNull
    @Override
    public byte[] javaGetPublicKeyRepresentation() {
        return new byte[0];
    }

    @NotNull
    @Override
    public Key javaGetPublicKey() {
        return null;
    }

    @NotNull
    @Override
    public JsonElement javaVerifyJws() {
        return null;
    }

    @NotNull
    @Override
    public byte[] javaVerifyRaw() {
        return new byte[0];
    }

    @NotNull
    @Override
    public String javaSignJws(@NotNull byte[] plaintext, @NotNull Map<String, String> headers) {
        return "";
    }

    @NotNull
    @Override
    public Object javaSignRaw(@NotNull byte[] plaintext) {
        return null;
    }

    @NotNull
    @Override
    public String javaExportPEM() {
        return "";
    }

    @NotNull
    @Override
    public JsonObject javaExportJWKObject() {
        return null;
    }

    @NotNull
    @Override
    public String javaExportJWK() {
        return "";
    }

    @NotNull
    @Override
    public String javaGetThumbprint() {
        return "";
    }

    @NotNull
    @Override
    public String javaGetKeyId() {
        return "";
    }

    @Override
    public boolean javaHasPrivateKey() {
        return false;
    }

    @NotNull
    @Override
    public KeyType javaGetKeyType() {
        return null;
    }
}

@philpotisk philpotisk linked a pull request Apr 29, 2024 that will close this issue
@saujam
Copy link
Author

saujam commented May 6, 2024

What is the release version for java key implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants