mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-25 02:55:23 +00:00
feat: add config merging
This commit is contained in:
parent
09a9fce480
commit
a6ebfd61c5
@ -41,7 +41,8 @@ class InstrumentedTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun jni_user_profile_c_api() {
|
fun jni_user_profile_c_api() {
|
||||||
val userProfile = UserProfile.newInstance(keyPair.secretKey)
|
val edSk = keyPair.secretKey
|
||||||
|
val userProfile = UserProfile.newInstance(edSk)
|
||||||
|
|
||||||
// these should be false as empty config
|
// these should be false as empty config
|
||||||
assertFalse(userProfile.needsPush())
|
assertFalse(userProfile.needsPush())
|
||||||
@ -123,7 +124,46 @@ class InstrumentedTests {
|
|||||||
|
|
||||||
assertArrayEquals(expectedDump, dump)
|
assertArrayEquals(expectedDump, dump)
|
||||||
|
|
||||||
|
val newConf = UserProfile.newInstance(edSk)
|
||||||
|
|
||||||
|
val accepted = newConf.merge(arrayOf(expectedPush1Encrypted))
|
||||||
|
assertEquals(1, accepted)
|
||||||
|
|
||||||
|
assertTrue(newConf.needsDump())
|
||||||
|
assertFalse(newConf.needsPush())
|
||||||
|
val _ignore = newConf.dump()
|
||||||
|
assertFalse(newConf.needsDump())
|
||||||
|
|
||||||
|
|
||||||
|
userProfile.setName("Nibbler")
|
||||||
|
newConf.setName("Raz")
|
||||||
|
newConf.setPic(UserPic("http://new.example.com/pic", "qwertyuio".encodeToByteArray()))
|
||||||
|
|
||||||
|
val conf = userProfile.push()
|
||||||
|
val conf2 = newConf.push()
|
||||||
|
|
||||||
|
val dump1 = userProfile.dump()
|
||||||
|
val dump2 = userProfile.dump()
|
||||||
|
|
||||||
|
assertFalse(conf.config.contentEquals(conf2.config))
|
||||||
|
|
||||||
|
newConf.merge(arrayOf(conf.config))
|
||||||
|
userProfile.merge(arrayOf(conf2.config))
|
||||||
|
|
||||||
|
assertTrue(newConf.needsPush())
|
||||||
|
assertTrue(userProfile.needsPush())
|
||||||
|
|
||||||
|
val newSeq1 = userProfile.push()
|
||||||
|
val newSeq2 = newConf.push()
|
||||||
|
|
||||||
|
assertEquals(3, newSeq1.seqNo)
|
||||||
|
assertEquals(3, newSeq2.seqNo)
|
||||||
|
|
||||||
|
assertEquals("Nibbler", newConf.getName())
|
||||||
|
assertEquals("Nibbler", userProfile.getName())
|
||||||
|
|
||||||
userProfile.free()
|
userProfile.free()
|
||||||
|
newConf.free()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -186,9 +186,23 @@ Java_network_loki_messenger_libsession_1util_ConfigBase_encryptionDomain(JNIEnv
|
|||||||
return env->NewStringUTF(conf->encryption_domain());
|
return env->NewStringUTF(conf->encryption_domain());
|
||||||
}
|
}
|
||||||
extern "C"
|
extern "C"
|
||||||
JNIEXPORT jbyteArray JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_network_loki_messenger_libsession_1util_ConfigBase_decrypt(JNIEnv *env, jobject thiz,
|
Java_network_loki_messenger_libsession_1util_ConfigBase_confirmPushed(JNIEnv *env, jobject thiz,
|
||||||
jbyteArray encrypted) {
|
jlong seq_no) {
|
||||||
auto profile = ptrToProfile(env, thiz);
|
auto conf = ptrToConfigBase(env, thiz);
|
||||||
auto encrypted_bytes = ustring_from_bytes(env, encrypted);
|
conf->confirm_pushed(seq_no);
|
||||||
|
}
|
||||||
|
extern "C"
|
||||||
|
JNIEXPORT jint JNICALL
|
||||||
|
Java_network_loki_messenger_libsession_1util_ConfigBase_merge(JNIEnv *env, jobject thiz,
|
||||||
|
jobjectArray to_merge) {
|
||||||
|
auto conf = ptrToConfigBase(env, thiz);
|
||||||
|
size_t number = env->GetArrayLength(to_merge);
|
||||||
|
std::vector<session::ustring> configs = {};
|
||||||
|
for (int i = 0; i < number; i++) {
|
||||||
|
auto jArr = (jbyteArray) env->GetObjectArrayElement(to_merge, i);
|
||||||
|
auto bytes = ustring_from_bytes(env, jArr);
|
||||||
|
configs.push_back(bytes);
|
||||||
|
}
|
||||||
|
return conf->merge(configs);
|
||||||
}
|
}
|
@ -16,7 +16,8 @@ sealed class ConfigBase(protected val /* yucky */ pointer: Long) {
|
|||||||
external fun push(): ConfigWithSeqNo
|
external fun push(): ConfigWithSeqNo
|
||||||
external fun dump(): ByteArray
|
external fun dump(): ByteArray
|
||||||
external fun encryptionDomain(): String
|
external fun encryptionDomain(): String
|
||||||
external fun decrypt(encrypted: ByteArray): ByteArray
|
external fun confirmPushed(seqNo: Long)
|
||||||
|
external fun merge(toMerge: Array<ByteArray>): Int
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserProfile(pointer: Long): ConfigBase(pointer) {
|
class UserProfile(pointer: Long): ConfigBase(pointer) {
|
||||||
|
Loading…
Reference in New Issue
Block a user