Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
alias(libs.plugins.android.library) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlinx.serialization) apply false
val kotlinVersion = "2.2.21"

id("com.android.library") version "8.13.1" apply false
id("org.jetbrains.kotlin.android") version kotlinVersion apply false
id("org.jetbrains.kotlin.plugin.serialization") version kotlinVersion apply false
}
20 changes: 0 additions & 20 deletions gradle/libs.versions.toml

This file was deleted.

29 changes: 15 additions & 14 deletions library/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import com.google.protobuf.gradle.id
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlinx.serialization)
id("com.android.library")
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.plugin.serialization")
id("maven-publish")

alias(libs.plugins.protobuf.compiler)
id("com.google.protobuf") version "0.9.5"
}

group = "org.sessionfoundation"
version = System.getenv("VERSION") ?: "dev-snapshot"

val protobufVersion = "4.33.1"

android {
namespace = "org.sessionfoundation.libsession_util"
compileSdk = 35
Expand Down Expand Up @@ -81,7 +81,7 @@ kotlin {

protobuf {
protoc {
artifact = libs.protoc.get().toString()
artifact = "com.google.protobuf:protoc:$protobufVersion"
}

plugins {
Expand Down Expand Up @@ -133,15 +133,16 @@ publishing {
}

dependencies {
androidTestImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.runner)
androidTestImplementation(libs.androidx.test.rules)
androidTestImplementation(libs.androidx.test.ext)

implementation(libs.androidx.annotations)
implementation(libs.kotlinx.serialization.core)
androidTestImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test:runner:1.7.0")
androidTestImplementation("androidx.test:rules:1.7.0")
androidTestImplementation("androidx.test.ext:junit:1.3.0")

implementation("androidx.annotation:annotation:1.9.1")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.9.0")

api(libs.protobuf.java)
api("com.google.protobuf:protobuf-java:$protobufVersion")

protobuf(files("../libsession-util/proto/SessionProtos.proto"))
}
39 changes: 2 additions & 37 deletions library/src/main/cpp/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ Java_network_loki_messenger_libsession_1util_protocol_SessionProtocol_encodeForG
extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_protocol_SessionProtocol_decodeForCommunity(
JNIEnv *env, jobject thiz, jbyteArray payload, jlong now_epoch_ms,
JNIEnv *env, jobject thiz, jbyteArray payload, jlong timestamp_ms,
jbyteArray pro_backend_pub_key) {
return run_catching_cxx_exception_or_throws<jobject>(env, [=] {
jni_utils::JavaByteArrayRef payload_ref(env, payload);

auto decoded = session::decode_for_community(
payload_ref.get(),
std::chrono::sys_time<std::chrono::milliseconds>{
std::chrono::milliseconds{now_epoch_ms}},
std::chrono::milliseconds{timestamp_ms}},
*java_to_cpp_array<32>(env, pro_backend_pub_key)
);

Expand Down Expand Up @@ -194,7 +194,6 @@ Java_network_loki_messenger_libsession_1util_protocol_SessionProtocol_decodeFor1
jobject thiz,
jbyteArray key,
jbyteArray payload,
jlong now_epoch_ms,
jbyteArray pro_backend_pub_key) {
return run_catching_cxx_exception_or_throws<jobject>(env, [=] {
JavaByteArrayRef key_ref(env, key);
Expand All @@ -208,8 +207,6 @@ Java_network_loki_messenger_libsession_1util_protocol_SessionProtocol_decodeFor1
return serializeDecodedEnvelope(env, session::decode_envelope(
decode_key,
JavaByteArrayRef(env, payload).get(),
std::chrono::sys_time<std::chrono::milliseconds>{
std::chrono::milliseconds{now_epoch_ms}},
*java_to_cpp_array<32>(env, pro_backend_pub_key)
)).release();
});
Expand All @@ -222,7 +219,6 @@ Java_network_loki_messenger_libsession_1util_protocol_SessionProtocol_decodeForG
jobject thiz,
jbyteArray payload,
jbyteArray my_ed25519_priv_key,
jlong now_epoch_ms,
jbyteArray group_ed25519_public_key,
jobjectArray group_ed25519_private_keys,
jbyteArray pro_backend_pub_key) {
Expand All @@ -245,38 +241,7 @@ Java_network_loki_messenger_libsession_1util_protocol_SessionProtocol_decodeForG
return serializeDecodedEnvelope(env, session::decode_envelope(
decode_key,
JavaByteArrayRef(env, payload).get(),
std::chrono::sys_time<std::chrono::milliseconds>{
std::chrono::milliseconds{now_epoch_ms}},
*java_to_cpp_array<32>(env, pro_backend_pub_key)
)).release();
});
}

extern "C"
JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_protocol_SessionProtocol_proFeaturesForMessage(
JNIEnv *env, jobject thiz, jstring message_body) {
return run_catching_cxx_exception_or_throws<jobject>(env, [=] {
JavaCharsRef message_ref(env, message_body);

auto features = session::pro_features_for_utf16(
reinterpret_cast<const char16_t *>(message_ref.chars()),
message_ref.size()
);

static BasicJavaClassInfo class_info(
env,
"network/loki/messenger/libsession_util/protocol/ProFeaturesForMsg",
"(ILjava/lang/String;JI)V"
);

return env->NewObject(
class_info.java_class,
class_info.constructor,
static_cast<jint>(features.status),
features.error.empty() ? nullptr : env->NewStringUTF(std::string(features.error).c_str()),
static_cast<jlong>(features.bitset.data),
static_cast<jint>(features.codepoint_count)
);
});
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ object SessionProtocol : LibSessionUtilCApi() {
external fun decodeFor1o1(
myEd25519PrivKey: ByteArray,
payload: ByteArray,
nowEpochMs: Long,
proBackendPubKey: ByteArray, // 32 bytes backend key
): DecodedEnvelope

Expand All @@ -34,7 +33,7 @@ object SessionProtocol : LibSessionUtilCApi() {

external fun decodeForCommunity(
payload: ByteArray,
nowEpochMs: Long,
timestampMs: Long,
proBackendPubKey: ByteArray, // 32 bytes backend key
): DecodedCommunityMessage

Expand All @@ -50,21 +49,8 @@ object SessionProtocol : LibSessionUtilCApi() {
external fun decodeForGroup(
payload: ByteArray,
myEd25519PrivKey: ByteArray,
nowEpochMs: Long,
groupEd25519PublicKey: ByteArray, // 33 bytes 03 prefixed key
groupEd25519PrivateKeys: Array<ByteArray>, // all available group private keys
proBackendPubKey: ByteArray, // 32 bytes backend key
): DecodedEnvelope

private external fun proFeaturesForMessage(
messageBody: String,
proposedFeatures: Long
): ProFeaturesForMsg

/**
* Determines which Pro features shall be applied to a message based on its content and the proposed features.
*/
fun proFeaturesForMessage(
messageBody: String,
): ProFeaturesForMsg = proFeaturesForMessage(messageBody)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class Bytes(val data: ByteArray) {
return data.contentHashCode()
}

override fun toString(): String {
return "Bytes(${data.size} bytes)"
}

companion object {
fun ByteArray.toBytes(): Bytes {
return Bytes(this)
Expand Down
1 change: 0 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ dependencyResolutionManagement {
}
}

rootProject.name = "libsession-util-android"
include(":library")
project(":library").name = "libsession-util-android"