mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-28 20:45:17 +00:00
feat: adding contacts logic, fixing up linter issues, starting contacts tests with native functions
This commit is contained in:
parent
68b62c3e80
commit
ca7d482050
@ -34,7 +34,8 @@ class InstrumentedTests {
|
||||
|
||||
@Test
|
||||
fun jni_contacts() {
|
||||
val userProfile = UserProfile.newInstance(keyPair.secretKey)
|
||||
val contacts = Contacts.newInstance(keyPair.secretKey)
|
||||
val definitelyRealId = Hex.fromStringCondensed("050000000000000000000000000000000000000000000000000000000000000000")
|
||||
|
||||
}
|
||||
|
||||
|
@ -55,6 +55,8 @@ Java_network_loki_messenger_libsession_1util_ConfigBase_confirmPushed(JNIEnv *en
|
||||
conf->confirm_pushed(seq_no);
|
||||
}
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma ide diagnostic ignored "bugprone-reserved-identifier"
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_ConfigBase_merge___3_3B(JNIEnv *env, jobject thiz,
|
||||
jobjectArray to_merge) {
|
||||
@ -76,5 +78,5 @@ Java_network_loki_messenger_libsession_1util_ConfigBase_merge___3B(JNIEnv *env,
|
||||
std::vector<session::ustring> configs = {util::ustring_from_bytes(env, to_merge)};
|
||||
return conf->merge(configs);
|
||||
}
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
}
|
@ -36,4 +36,36 @@ Java_network_loki_messenger_libsession_1util_Contacts_erase(JNIEnv *env, jobject
|
||||
jstring session_id) {
|
||||
auto contacts = ptrToContacts(env, thiz);
|
||||
return contacts->erase(env->GetStringUTFChars(session_id, nullptr));
|
||||
}
|
||||
}
|
||||
extern "C"
|
||||
#pragma clang diagnostic push
|
||||
#pragma ide diagnostic ignored "bugprone-reserved-identifier"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_Contacts_00024Companion_newInstance___3B(JNIEnv *env,
|
||||
jobject thiz,
|
||||
jbyteArray ed25519_secret_key) {
|
||||
auto secret_key = util::ustring_from_bytes(env, ed25519_secret_key);
|
||||
auto* contacts = new session::config::Contacts(secret_key, std::nullopt);
|
||||
|
||||
jclass contactsClass = env->FindClass("network/loki/messenger/libsession_util/Contacts");
|
||||
jmethodID constructor = env->GetMethodID(contactsClass, "<init>", "(J)V");
|
||||
jobject newConfig = env->NewObject(contactsClass, constructor, reinterpret_cast<jlong>(contacts));
|
||||
|
||||
return newConfig;
|
||||
}
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_Contacts_00024Companion_newInstance___3B_3B(
|
||||
JNIEnv *env, jobject thiz, jbyteArray ed25519_secret_key, jbyteArray initial_dump) {
|
||||
auto secret_key = util::ustring_from_bytes(env, ed25519_secret_key);
|
||||
auto initial = util::ustring_from_bytes(env, initial_dump);
|
||||
|
||||
auto* contacts = new session::config::Contacts(secret_key, initial);
|
||||
|
||||
jclass contactsClass = env->FindClass("network/loki/messenger/libsession_util/Contacts");
|
||||
jmethodID constructor = env->GetMethodID(contactsClass, "<init>", "(J)V");
|
||||
jobject newConfig = env->NewObject(contactsClass, constructor, reinterpret_cast<jlong>(contacts));
|
||||
|
||||
return newConfig;
|
||||
}
|
||||
#pragma clang diagnostic pop
|
@ -2,6 +2,8 @@
|
||||
#include "util.h"
|
||||
|
||||
extern "C" {
|
||||
#pragma clang diagnostic push
|
||||
#pragma ide diagnostic ignored "bugprone-reserved-identifier"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_UserProfile_00024Companion_newInstance___3B_3B(
|
||||
JNIEnv *env, jobject thiz, jbyteArray ed25519_secret_key, jbyteArray initial_dump) {
|
||||
@ -30,6 +32,7 @@ Java_network_loki_messenger_libsession_1util_UserProfile_00024Companion_newInsta
|
||||
|
||||
return newConfig;
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_UserProfile_setName(
|
||||
|
@ -44,8 +44,8 @@ namespace util {
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_util_Sodium_ed25519KeyPair(JNIEnv *env, jobject thiz, jbyteArray seed) {
|
||||
std::array<unsigned char, 32> ed_pk;
|
||||
std::array<unsigned char, 64> ed_sk;
|
||||
std::array<unsigned char, 32> ed_pk; // NOLINT(cppcoreguidelines-pro-type-member-init)
|
||||
std::array<unsigned char, 64> ed_sk; // NOLINT(cppcoreguidelines-pro-type-member-init)
|
||||
auto seed_bytes = util::ustring_from_bytes(env, seed);
|
||||
crypto_sign_ed25519_seed_keypair(ed_pk.data(), ed_sk.data(), seed_bytes.data());
|
||||
|
||||
@ -57,4 +57,16 @@ Java_network_loki_messenger_libsession_1util_util_Sodium_ed25519KeyPair(JNIEnv *
|
||||
|
||||
jobject return_obj = env->NewObject(kp_class, kp_constructor, pk_jarray, sk_jarray);
|
||||
return return_obj;
|
||||
}
|
||||
extern "C"
|
||||
JNIEXPORT jbyteArray JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_util_Sodium_ed25519PkToCurve25519(JNIEnv *env,
|
||||
jobject thiz,
|
||||
jbyteArray pk) {
|
||||
auto ed_pk = util::ustring_from_bytes(env, pk);
|
||||
std::array<unsigned char, 32> curve_pk; // NOLINT(cppcoreguidelines-pro-type-member-init)
|
||||
crypto_sign_ed25519_pk_to_curve25519(curve_pk.data(), ed_pk.data());
|
||||
|
||||
jbyteArray curve_pk_jarray = util::bytes_from_ustring(env, session::ustring_view {curve_pk.data(), curve_pk.size()});
|
||||
return curve_pk_jarray;
|
||||
}
|
@ -26,6 +26,14 @@ sealed class ConfigBase(protected val /* yucky */ pointer: Long) {
|
||||
}
|
||||
|
||||
class Contacts(pointer: Long) : ConfigBase(pointer) {
|
||||
companion object {
|
||||
init {
|
||||
System.loadLibrary("session_util")
|
||||
}
|
||||
external fun newInstance(ed25519SecretKey: ByteArray): Contacts
|
||||
external fun newInstance(ed25519SecretKey: ByteArray, initialDump: ByteArray): Contacts
|
||||
}
|
||||
|
||||
external fun get(sessionId: String): Contact?
|
||||
external fun getOrCreate(sessionId: String): Contact
|
||||
external fun set(contact: Contact)
|
||||
|
@ -5,4 +5,5 @@ object Sodium {
|
||||
System.loadLibrary("session_util")
|
||||
}
|
||||
external fun ed25519KeyPair(seed: ByteArray): KeyPair
|
||||
external fun ed25519PkToCurve25519(pk: ByteArray): ByteArray
|
||||
}
|
Loading…
Reference in New Issue
Block a user