feat: trying to solve byte array null error
This commit is contained in:
parent
faf1ba85fc
commit
59c5588370
|
@ -584,7 +584,7 @@ class InstrumentedTests {
|
|||
@Test
|
||||
fun testGroupInfo() {
|
||||
val (public, secret) = keyPair
|
||||
val conf = GroupInfoConfig.newInstance(public, secret)
|
||||
val conf = GroupInfoConfig.newInstance(public, secret, null)
|
||||
conf.setName("New Group")
|
||||
assertEquals("New Group", conf.getName())
|
||||
}
|
||||
|
|
|
@ -4,18 +4,20 @@
|
|||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_network_loki_messenger_libsession_1util_GroupInfoConfig_00024Companion_newInstance___3B_3B_3B(
|
||||
JNIEnv *env, jobject thiz, jbyteArray pub_key, jbyteArray secret_key,
|
||||
jbyteArray initial_dump) {
|
||||
Java_network_loki_messenger_libsession_1util_GroupInfoConfig_00024Companion_newInstance(JNIEnv *env,
|
||||
jobject thiz,
|
||||
jbyteArray pub_key,
|
||||
jbyteArray secret_key,
|
||||
jbyteArray initial_dump) {
|
||||
std::lock_guard guard{util::util_mutex_};
|
||||
std::optional<session::ustring> secret_key_optional{std::nullopt};
|
||||
std::optional<session::ustring> initial_dump_optional{std::nullopt};
|
||||
auto pub_key_bytes = util::ustring_from_bytes(env, pub_key);
|
||||
if (secret_key != nullptr) {
|
||||
if (env->GetArrayLength(secret_key) == 32 || env->GetArrayLength(secret_key) == 64) {
|
||||
auto secret_key_bytes = util::ustring_from_bytes(env, secret_key);
|
||||
secret_key_optional = secret_key_bytes;
|
||||
}
|
||||
if (pub_key != nullptr) {
|
||||
if (env->GetArrayLength(initial_dump) > 0) {
|
||||
auto initial_dump_bytes = util::ustring_from_bytes(env, initial_dump);
|
||||
initial_dump_optional = initial_dump_bytes;
|
||||
}
|
||||
|
|
|
@ -17,11 +17,11 @@ Java_network_loki_messenger_libsession_1util_GroupKeysConfig_00024Companion_newI
|
|||
auto pub_key_bytes = util::ustring_from_bytes(env, group_public_key);
|
||||
std::optional<session::ustring> secret_key_optional{std::nullopt};
|
||||
std::optional<session::ustring> initial_dump_optional{std::nullopt};
|
||||
if (group_secret_key != nullptr) {
|
||||
if (env->GetArrayLength(group_secret_key) == 32 || env->GetArrayLength(group_secret_key) == 64) {
|
||||
auto secret_key_bytes = util::ustring_from_bytes(env, group_secret_key);
|
||||
secret_key_optional = secret_key_bytes;
|
||||
}
|
||||
if (initial_dump != nullptr) {
|
||||
if (env->GetArrayLength(initial_dump) > 0) {
|
||||
auto initial_dump_bytes = util::ustring_from_bytes(env, initial_dump);
|
||||
initial_dump_optional = initial_dump_bytes;
|
||||
}
|
||||
|
|
|
@ -9,11 +9,11 @@ Java_network_loki_messenger_libsession_1util_GroupMemberConfig_00024Companion_ne
|
|||
auto pub_key_bytes = util::ustring_from_bytes(env, pub_key);
|
||||
std::optional<session::ustring> secret_key_optional{std::nullopt};
|
||||
std::optional<session::ustring> initial_dump_optional{std::nullopt};
|
||||
if (secret_key != nullptr) {
|
||||
if (env->GetArrayLength(secret_key) == 32 || env->GetArrayLength(secret_key) == 64) {
|
||||
auto secret_key_bytes = util::ustring_from_bytes(env, secret_key);
|
||||
secret_key_optional = secret_key_bytes;
|
||||
}
|
||||
if (initial_dump != nullptr) {
|
||||
if (env->GetArrayLength(initial_dump) > 0) {
|
||||
auto initial_dump_bytes = util::ustring_from_bytes(env, initial_dump);
|
||||
initial_dump_optional = initial_dump_bytes;
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ namespace util {
|
|||
jstring name = env->NewStringUTF(member.name.data());
|
||||
jboolean invite_failed = member.invite_failed();
|
||||
jboolean invite_pending = member.invite_pending();
|
||||
jboolean promoted = member.promoted();
|
||||
jboolean admin = member.admin;
|
||||
jboolean promotion_failed = member.promotion_failed();
|
||||
jboolean promotion_pending = member.promotion_pending();
|
||||
return env->NewObject(group_member_class,
|
||||
|
@ -131,7 +131,7 @@ namespace util {
|
|||
user_pic,
|
||||
invite_failed,
|
||||
invite_pending,
|
||||
promoted,
|
||||
admin,
|
||||
promotion_failed,
|
||||
promotion_pending);
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ namespace util {
|
|||
jfieldID user_pic_field = env->GetFieldID(group_member_class,"profilePicture", "Lnetwork/loki/messenger/libsession_util/util/UserPic;");
|
||||
jfieldID invite_failed_field = env->GetFieldID(group_member_class, "inviteFailed", "Z");
|
||||
jfieldID invite_pending_field = env->GetFieldID(group_member_class, "invitePending", "Z");
|
||||
jfieldID promoted_field = env->GetFieldID(group_member_class, "promoted", "Z");
|
||||
jfieldID admin_field = env->GetFieldID(group_member_class, "admin", "Z");
|
||||
jfieldID promotion_failed_field = env->GetFieldID(group_member_class, "promotionFailed", "Z");
|
||||
jfieldID promotion_pending_field = env->GetFieldID(group_member_class, "promotionPending", "Z");
|
||||
auto session_id = (jstring)env->GetObjectField(member, session_id_field);
|
||||
|
@ -156,14 +156,15 @@ namespace util {
|
|||
auto pic_key = ustring_from_bytes(env, user_pic.second);
|
||||
auto invite_failed = env->GetBooleanField(member, invite_failed_field);
|
||||
auto invite_pending = env->GetBooleanField(member, invite_pending_field);
|
||||
auto promoted = env->GetBooleanField(member, promoted_field);
|
||||
auto admin = env->GetBooleanField(member, admin_field);
|
||||
auto promotion_failed = env->GetBooleanField(member, promotion_failed_field);
|
||||
auto promotion_pending = env->GetBooleanField(member, promotion_pending_field);
|
||||
|
||||
// set up the object
|
||||
session::config::groups::member group_member(session_id_bytes);
|
||||
group_member.set_name(name_bytes);
|
||||
group_member.profile_picture = session::config::profile_pic{url_bytes, pic_key};
|
||||
group_member.name = name_bytes;
|
||||
group_member.profile_picture.url = url_bytes;
|
||||
group_member.profile_picture.set_key(pic_key);
|
||||
|
||||
if (invite_pending) {
|
||||
group_member.set_invited(false);
|
||||
|
@ -177,7 +178,7 @@ namespace util {
|
|||
group_member.set_promoted(true);
|
||||
}
|
||||
|
||||
// set promotion TODO
|
||||
group_member.admin = admin;
|
||||
|
||||
env->ReleaseStringUTFChars(user_pic.first, url_bytes);
|
||||
env->ReleaseStringUTFChars(session_id, session_id_bytes);
|
||||
|
|
|
@ -26,6 +26,8 @@ sealed class ConfigBase(protected val /* yucky */ pointer: Long) {
|
|||
is ConversationVolatileConfig -> Kind.CONVO_INFO_VOLATILE
|
||||
is UserGroupsConfig -> Kind.GROUPS
|
||||
is GroupInfoConfig -> Kind.CLOSED_GROUP_INFO
|
||||
is GroupKeysConfig -> Kind.ENCRYPTION_KEYS
|
||||
is GroupMemberConfig -> Kind.CLOSED_GROUP_MEMBERS
|
||||
}
|
||||
|
||||
// TODO: time in future to activate (hardcoded to 1st jan 2024 for testing, change before release)
|
||||
|
@ -213,8 +215,8 @@ class GroupInfoConfig(pointer: Long): ConfigBase(pointer) {
|
|||
|
||||
external fun newInstance(
|
||||
pubKey: ByteArray,
|
||||
secretKey: ByteArray?,
|
||||
initialDump: ByteArray?
|
||||
secretKey: ByteArray,
|
||||
initialDump: ByteArray
|
||||
): GroupInfoConfig
|
||||
}
|
||||
|
||||
|
@ -242,8 +244,8 @@ class GroupMemberConfig(pointer: Long): ConfigBase(pointer) {
|
|||
}
|
||||
external fun newInstance(
|
||||
pubKey: ByteArray,
|
||||
secretKey: ByteArray?,
|
||||
initialDump: ByteArray?
|
||||
secretKey: ByteArray = byteArrayOf(),
|
||||
initialDump: ByteArray = byteArrayOf()
|
||||
): GroupMemberConfig
|
||||
}
|
||||
external fun all(): Stack<GroupMember>
|
||||
|
@ -261,8 +263,8 @@ class GroupKeysConfig(pointer: Long): ConfigBase(pointer) {
|
|||
external fun newInstance(
|
||||
userSecretKey: ByteArray,
|
||||
groupPublicKey: ByteArray,
|
||||
groupSecretKey: ByteArray?,
|
||||
initialDump: ByteArray?,
|
||||
groupSecretKey: ByteArray = byteArrayOf(),
|
||||
initialDump: ByteArray = byteArrayOf(),
|
||||
info: GroupInfoConfig,
|
||||
members: GroupMemberConfig
|
||||
): GroupKeysConfig
|
||||
|
|
|
@ -6,7 +6,7 @@ data class GroupMember(
|
|||
val profilePicture: UserPic?,
|
||||
val inviteFailed: Boolean,
|
||||
val invitePending: Boolean,
|
||||
val promoted: Boolean,
|
||||
val admin: Boolean,
|
||||
val promotionFailed: Boolean,
|
||||
val promotionPending: Boolean,
|
||||
)
|
Loading…
Reference in New Issue