From c8c7a8ad19d3238ae3c0c7db4eaff165748a6a1e Mon Sep 17 00:00:00 2001 From: ylecollen Date: Tue, 3 Jan 2017 10:46:56 +0100 Subject: -> simplify OlmSession.DecryptMessage -> Always use javaCStringToUtf8 to convert byte array to String --- .../OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp | 23 ++++++---------------- 1 file changed, 6 insertions(+), 17 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 28edae1..0797ae6 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 @@ -580,7 +580,7 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz * @param aEncryptedMsg message to decrypt * @return decrypted message if operation succeed, null otherwise */ -JNIEXPORT jstring OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jobject aEncryptedMsg, jboolean aIsUtf8ConversionRequired) +JNIEXPORT jstring OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jobject aEncryptedMsg) { jstring decryptedMsgRetValue = 0; jclass encryptedMsgJClass = 0; @@ -668,26 +668,15 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject t } else { - // UTF-8 conversion workaround for issue on Android versions older than Marshmallow (23) - if (aIsUtf8ConversionRequired) + decryptedMsgRetValue = javaCStringToUtf8(env, plainTextMsgPtr, plaintextLength); + + if (!decryptedMsgRetValue) { - decryptedMsgRetValue = javaCStringToUtf8(env, plainTextMsgPtr, plaintextLength); - if(0 == decryptedMsgRetValue) - { - LOGE(" ## decryptMessageJni(): UTF-8 Conversion failure - javaCStringToUtf8() returns null"); - } - else - { - LOGD(" ## decryptMessageJni(): UTF-8 Conversion - decrypted returnedLg=%lu OK",static_cast(plaintextLength)); - } + LOGE(" ## decryptMessageJni(): UTF-8 Conversion failure - javaCStringToUtf8() returns null"); } else { - // update decrypted buffer size - plainTextMsgPtr[plaintextLength] = static_cast('\0'); - - LOGD("## decryptMessageJni(): decrypted returnedLg=%lu plainTextMsgPtr=%s",static_cast(plaintextLength), (char*)(plainTextMsgPtr)); - decryptedMsgRetValue = env->NewStringUTF((const char*)(plainTextMsgPtr)); + LOGD(" ## decryptMessageJni(): UTF-8 Conversion - decrypted returnedLg=%lu OK",static_cast(plaintextLength)); } } } -- cgit v1.2.3