fix: tests pass now

This commit is contained in:
0x330a 2022-12-07 12:14:50 +11:00
parent 36b091c640
commit 857d0a7ef1
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C
4 changed files with 60 additions and 33 deletions

@ -1 +1 @@
Subproject commit 57f6bbd91bb4b1f2d115b75e8beb850153bb6767
Subproject commit 462e2b6808122919141e8636822cbf00f9f587e9

View File

@ -1,6 +1,5 @@
package network.loki.messenger.libsession_util
import android.util.Log
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import network.loki.messenger.libsession_util.util.KeyPair
@ -21,7 +20,8 @@ class InstrumentedTests {
private val keyPair: KeyPair
get() {
val seed = Hex.fromStringCondensed("0123456789abcdef0123456789abcdef00000000000000000000000000000000")
val seed =
Hex.fromStringCondensed("0123456789abcdef0123456789abcdef00000000000000000000000000000000")
return Sodium.ed25519KeyPair(seed)
}
@ -51,8 +51,8 @@ class InstrumentedTests {
assertNull(userProfile.getName())
// Don't need to push yet so this is just for testing
val (toPush, seqNo) = userProfile.push()
assertEquals("d1:#i0e1:&de1:<le1:=dee", toPush.decodeToString())
val (_, seqNo) = userProfile.push() // disregarding encrypted
assertEquals("UserProfile", userProfile.encryptionDomain())
assertEquals(0, seqNo)
// This should also be unset:
@ -76,8 +76,10 @@ class InstrumentedTests {
assertTrue(userProfile.needsDump())
val (newToPush, newSeqNo) = userProfile.push()
val expHash0 = Hex.fromStringCondensed("ea173b57beca8af18c3519a7bbf69c3e7a05d1c049fa9558341d8ebb48b0c965")
val expectedPush1 = ("d" +
val expHash0 =
Hex.fromStringCondensed("ea173b57beca8af18c3519a7bbf69c3e7a05d1c049fa9558341d8ebb48b0c965")
val expectedPush1Decrypted = ("d" +
"1:#" + "i1e"+
"1:&" + "d"+
"1:n" + "6:Kallie"+
@ -94,8 +96,17 @@ class InstrumentedTests {
"e" +
"e").encodeToByteArray()
val expectedPush1Encrypted = Hex.fromStringCondensed(
"a2952190dcb9797bc48e48f6dc7b3254d004bde9091cfc9ec3433cbc5939a3726deb04f58a546d7d79e6f8" +
"0ea185d43bf93278398556304998ae882304075c77f15c67f9914c4d10005a661f29ff7a79e0a9de7f2172" +
"5ba3b5a6c19eaa3797671b8fa4008d62e9af2744629cbb46664c4d8048e2867f66ed9254120371bdb24e95" +
"b2d92341fa3b1f695046113a768ceb7522269f937ead5591bfa8a5eeee3010474002f2db9de043f0f0d1cf" +
"b1066a03e7b5d6cfb70a8f84a20cd2df5a510cd3d175708015a52dd4a105886d916db0005dbea5706e5a5d" +
"c37ffd0a0ca2824b524da2e2ad181a48bb38e21ed9abe136014a4ee1e472cb2f53102db2a46afa9d68"
)
assertEquals(1, newSeqNo)
assertArrayEquals(expectedPush1, newToPush)
assertArrayEquals(expectedPush1Encrypted, newToPush)
// We haven't dumped, so still need to dump:
assertTrue(userProfile.needsDump())
// We did call push but we haven't confirmed it as stored yet, so this will still return true:
@ -106,8 +117,8 @@ class InstrumentedTests {
assertFalse(userProfile.needsDump())
val expectedDump = ("d" +
"1:!i2e" +
"1:$").encodeToByteArray() + expectedPush1.size.toString().encodeToByteArray() +
":".encodeToByteArray() + expectedPush1 +
"1:$").encodeToByteArray() + expectedPush1Decrypted.size.toString().encodeToByteArray() +
":".encodeToByteArray() + expectedPush1Decrypted +
"e".encodeToByteArray()
assertArrayEquals(expectedDump, dump)

View File

@ -129,7 +129,7 @@ Java_network_loki_messenger_libsession_1util_UserProfile_getPic(JNIEnv *env, job
auto pic = profile->get_profile_pic();
if (pic == std::nullopt) return nullptr;
// return nullptr if either parameter is null as per profile class
jclass returnObjectClass = env->FindClass("network/loki/messenger/libsession_util/UserPic");
jclass returnObjectClass = env->FindClass("network/loki/messenger/libsession_util/util/UserPic");
jmethodID constructor = env->GetMethodID(returnObjectClass, "<init>", "(Ljava/lang/String;[B)V");
jstring url = env->NewStringUTF(pic->url.data());
jbyteArray byteArray = bytes_from_ustring(env, pic->key);
@ -141,7 +141,7 @@ JNIEXPORT void JNICALL
Java_network_loki_messenger_libsession_1util_UserProfile_setPic(JNIEnv *env, jobject thiz,
jobject user_pic) {
auto profile = ptrToProfile(env, thiz);
jclass userPicClass = env->FindClass("network/loki/messenger/libsession_util/UserPic");
jclass userPicClass = env->FindClass("network/loki/messenger/libsession_util/util/UserPic");
jfieldID picField = env->GetFieldID(userPicClass, "url", "Ljava/lang/String;");
jfieldID keyField = env->GetFieldID(userPicClass, "key", "[B");
auto pic = (jstring)env->GetObjectField(user_pic, picField);
@ -167,14 +167,28 @@ Java_network_loki_messenger_libsession_1util_util_Sodium_ed25519KeyPair(JNIEnv *
std::array<unsigned char, 32> ed_pk;
std::array<unsigned char, 64> ed_sk;
auto seed_bytes = ustring_from_bytes(env, seed);
crypto_sign_ed25519_seed_keypair(ed_pk.data(), ed_sk.data(), seed_bytes.c_str());
crypto_sign_ed25519_seed_keypair(ed_pk.data(), ed_sk.data(), seed_bytes.data());
jclass kp_class = env->FindClass("network/loki/messenger/libsession_util/util/KeyPair");
jmethodID kp_constructor = env->GetMethodID(kp_class, "<init>", "([B[B)V");
jbyteArray pk_jarray = bytes_from_ustring(env, ed_pk.data());
jbyteArray sk_jarray = bytes_from_ustring(env, ed_sk.data());
jbyteArray pk_jarray = bytes_from_ustring(env, session::ustring_view {ed_pk.data(), ed_pk.size()});
jbyteArray sk_jarray = bytes_from_ustring(env, session::ustring_view {ed_sk.data(), ed_sk.size()});
jobject return_obj = env->NewObject(kp_class, kp_constructor, pk_jarray, sk_jarray);
return return_obj;
}
extern "C"
JNIEXPORT jstring JNICALL
Java_network_loki_messenger_libsession_1util_ConfigBase_encryptionDomain(JNIEnv *env,
jobject thiz) {
auto conf = ptrToConfigBase(env, thiz);
return env->NewStringUTF(conf->encryption_domain());
}
extern "C"
JNIEXPORT jbyteArray JNICALL
Java_network_loki_messenger_libsession_1util_ConfigBase_decrypt(JNIEnv *env, jobject thiz,
jbyteArray encrypted) {
auto profile = ptrToProfile(env, thiz);
auto encrypted_bytes = ustring_from_bytes(env, encrypted);
}

View File

@ -15,6 +15,8 @@ sealed class ConfigBase(protected val /* yucky */ pointer: Long) {
external fun needsDump(): Boolean
external fun push(): ConfigWithSeqNo
external fun dump(): ByteArray
external fun encryptionDomain(): String
external fun decrypt(encrypted: ByteArray): ByteArray
}
class UserProfile(pointer: Long): ConfigBase(pointer) {