From 9df5dd9c4257982d22955d6b9ee55fc1e9dcb25f Mon Sep 17 00:00:00 2001 From: ylecollen Date: Wed, 4 Jan 2017 18:30:35 +0100 Subject: The olm objects are serialized as byte[] instead of strings. --- .../OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp') diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp index f09ace6..7cde2cd 100644 --- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp +++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp @@ -754,7 +754,7 @@ JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobjec */ JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(getSessionIdentifierJni)(JNIEnv *env, jobject thiz) { - const char* errorMessage = NULL; + const char* errorMessage = NULL; jbyteArray returnValue = 0; LOGD("## getSessionIdentifierJni(): IN "); @@ -817,11 +817,11 @@ JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(getSessionIdentifierJni)(JNIEnv *env, * @param aKey key used to encrypt the serialized session data * @return a base64 string if operation succeed, null otherwise **/ -JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer) +JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer) { const char* errorMessage = NULL; + jbyteArray returnValue = 0; - jstring pickledDataRetValue = 0; jbyte* keyPtr = NULL; OlmSession* sessionPtr = NULL; @@ -847,7 +847,6 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, size_t pickledLength = olm_pickle_session_length(sessionPtr); size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer); LOGD(" ## serializeJni(): pickledLength=%lu keyLength=%lu",static_cast(pickledLength), static_cast(keyLength)); - LOGD(" ## serializeJni(): key=%s",(char const *)keyPtr); void *pickledPtr = malloc((pickledLength+1)*sizeof(uint8_t)); @@ -872,8 +871,10 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, { // build success output (static_cast(pickledPtr))[pickledLength] = static_cast('\0'); - pickledDataRetValue = env->NewStringUTF((const char*)pickledPtr); LOGD(" ## serializeJni(): success - result=%lu pickled=%s", static_cast(result), static_cast(pickledPtr)); + + returnValue = env->NewByteArray(pickledLength); + env->SetByteArrayRegion(returnValue, 0 , pickledLength, (jbyte*)pickledPtr); } free(pickledPtr); @@ -891,10 +892,9 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage); } - return pickledDataRetValue; + return returnValue; } - JNIEXPORT jstring OLM_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer) { OlmSession* sessionPtr = NULL; @@ -929,7 +929,6 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz size_t pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer); size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer); LOGD(" ## deserializeJni(): pickledLength=%lu keyLength=%lu",static_cast(pickledLength), static_cast(keyLength)); - LOGD(" ## deserializeJni(): key=%s",(char const *)keyPtr); LOGD(" ## deserializeJni(): pickled=%s",(char const *)pickledPtr); size_t result = olm_unpickle_session(sessionPtr, -- cgit v1.2.3