mirror of
https://github.com/signalapp/libsignal.git
synced 2024-09-20 20:03:07 +02:00
Merge pull request #127 from AsamK/identitykeypair_deserialize
Implement IdentityKeyPair Deserialize for Java
This commit is contained in:
commit
f81e679926
@ -96,6 +96,7 @@ public final class Native {
|
||||
|
||||
public static native byte[] HKDF_DeriveSecrets(int version, byte[] inputKeyMaterial, byte[] salt, byte[] info, int outputLength);
|
||||
|
||||
public static native long[] IdentityKeyPair_Deserialize(byte[] data);
|
||||
public static native byte[] IdentityKeyPair_Serialize(long publicKeyHandle, long privateKeyHandle);
|
||||
|
||||
public static native void NumericFingerprintGenerator_Destroy(long handle);
|
||||
|
@ -32,6 +32,10 @@ public class IdentityKey {
|
||||
this.publicKey = Curve.decodePoint(bytes, 0);
|
||||
}
|
||||
|
||||
public IdentityKey(long nativeHandle) {
|
||||
this.publicKey = new ECPublicKey(nativeHandle);
|
||||
}
|
||||
|
||||
public ECPublicKey getPublicKey() {
|
||||
return publicKey;
|
||||
}
|
||||
|
@ -23,6 +23,15 @@ public class IdentityKeyPair {
|
||||
this.privateKey = privateKey;
|
||||
}
|
||||
|
||||
public IdentityKeyPair(byte[] serialized) {
|
||||
long[] tuple = Native.IdentityKeyPair_Deserialize(serialized);
|
||||
long publicKeyHandle = tuple[0];
|
||||
long privateKeyHandle = tuple[1];
|
||||
|
||||
this.publicKey = new IdentityKey(publicKeyHandle);
|
||||
this.privateKey = new ECPrivateKey(privateKeyHandle);
|
||||
}
|
||||
|
||||
public IdentityKey getPublicKey() {
|
||||
return publicKey;
|
||||
}
|
||||
@ -31,7 +40,7 @@ public class IdentityKeyPair {
|
||||
return privateKey;
|
||||
}
|
||||
|
||||
byte[] serialize() {
|
||||
public byte[] serialize() {
|
||||
return Native.IdentityKeyPair_Serialize(this.publicKey.nativeHandle(), this.privateKey.nativeHandle());
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ def translate_to_java(typ):
|
||||
"jstring": "String",
|
||||
"JString": "String",
|
||||
"jbyteArray": "byte[]",
|
||||
"jlongArray": "long[]",
|
||||
"ObjectHandle": "long",
|
||||
"jint": "int",
|
||||
"jlong": "long",
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
use async_trait::async_trait;
|
||||
use jni::objects::{JClass, JObject, JString, JValue};
|
||||
use jni::sys::{jboolean, jbyteArray, jint, jlong, jobject, jstring};
|
||||
use jni::sys::{jboolean, jbyteArray, jint, jlong, jlongArray, jobject, jstring};
|
||||
use jni::JNIEnv;
|
||||
use std::convert::TryFrom;
|
||||
|
||||
@ -156,6 +156,26 @@ pub unsafe extern "C" fn Java_org_signal_client_internal_Native_IdentityKeyPair_
|
||||
})
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn Java_org_signal_client_internal_Native_IdentityKeyPair_1Deserialize(
|
||||
env: JNIEnv,
|
||||
_class: JClass,
|
||||
data: jbyteArray,
|
||||
) -> jlongArray {
|
||||
run_ffi_safe(&env, || {
|
||||
let data = env.convert_byte_array(data)?;
|
||||
let key = IdentityKeyPair::try_from(data.as_ref())?;
|
||||
|
||||
let public_key_handle = box_object(Ok(*key.identity_key().public_key()))?;
|
||||
let private_key_handle = box_object(Ok(*key.private_key()))?;
|
||||
let tuple = [public_key_handle, private_key_handle];
|
||||
|
||||
let result = env.new_long_array(2)?;
|
||||
env.set_long_array_region(result, 0, &tuple)?;
|
||||
Ok(result)
|
||||
})
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn Java_org_signal_client_internal_Native_DisplayableFingerprint_1Format(
|
||||
env: JNIEnv,
|
||||
|
Loading…
Reference in New Issue
Block a user