->Replace 2 spaces tabs by 4 spaces.
->fix the NULL and 0 pointer comparisons mixes
This commit is contained in:
parent
b03cdebfb5
commit
65352d05aa
8 changed files with 369 additions and 369 deletions
|
@ -19,7 +19,6 @@
|
|||
|
||||
using namespace AndroidOlmSdk;
|
||||
|
||||
|
||||
/**
|
||||
* Init memory allocation for account creation.
|
||||
* @return valid memory allocation, NULL otherwise
|
||||
|
@ -43,7 +42,6 @@ OlmAccount* initializeAccountMemory()
|
|||
return accountPtr;
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(createNewAccountJni)(JNIEnv *env, jobject thiz)
|
||||
{
|
||||
LOGD("## createNewAccountJni(): IN");
|
||||
|
@ -53,7 +51,6 @@ JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(createNewAccountJni)(JNIEnv *env, jobject t
|
|||
return (jlong)(intptr_t)accountPtr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Release the account allocation made by initializeAccountMemory().<br>
|
||||
* This method MUST be called when java counter part account instance is done.
|
||||
|
@ -147,7 +144,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(identityKeysJni)(JNIEnv *env, jobject
|
|||
jbyteArray byteArrayRetValue = NULL;
|
||||
OlmAccount* accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz);
|
||||
|
||||
if (NULL == accountPtr)
|
||||
if (!accountPtr)
|
||||
{
|
||||
LOGE("## identityKeys(): failure - invalid Account ptr=NULL");
|
||||
}
|
||||
|
@ -177,7 +174,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(identityKeysJni)(JNIEnv *env, jobject
|
|||
// allocate the byte array to be returned to java
|
||||
byteArrayRetValue = env->NewByteArray(identityKeysLength);
|
||||
|
||||
if(NULL == byteArrayRetValue)
|
||||
if (!byteArrayRetValue)
|
||||
{
|
||||
LOGE("## identityKeys(): failure - return byte array OOM");
|
||||
}
|
||||
|
@ -417,7 +414,7 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
|
|||
{
|
||||
LOGE("## signMessageJni(): failure - invalid aMessage param");
|
||||
}
|
||||
else if(NULL == (accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz)))
|
||||
else if(!(accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz)))
|
||||
{
|
||||
LOGE("## signMessageJni(): failure - invalid account ptr");
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env
|
|||
|
||||
LOGD("## releaseSessionJni(): InBound group session IN");
|
||||
|
||||
if(NULL == (sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
|
||||
if (!(sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
|
||||
{
|
||||
LOGE("## releaseSessionJni(): failure - invalid inbound group session instance");
|
||||
}
|
||||
|
@ -64,11 +64,11 @@ JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *
|
|||
LOGD("## createNewSessionJni(): inbound group session IN");
|
||||
sessionSize = olm_inbound_group_session_size();
|
||||
|
||||
if(0 == sessionSize)
|
||||
if (!sessionSize)
|
||||
{
|
||||
LOGE(" ## createNewSessionJni(): failure - inbound group session size = 0");
|
||||
}
|
||||
else if(NULL != (sessionPtr=(OlmInboundGroupSession*)malloc(sessionSize)))
|
||||
else if ((sessionPtr = (OlmInboundGroupSession*)malloc(sessionSize)))
|
||||
{
|
||||
sessionPtr = olm_inbound_group_session(sessionPtr);
|
||||
LOGD(" ## createNewSessionJni(): success - inbound group session size=%lu",static_cast<long unsigned int>(sessionSize));
|
||||
|
@ -95,15 +95,15 @@ JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSes
|
|||
|
||||
LOGD("## initInboundGroupSessionWithSessionKeyJni(): inbound group session IN");
|
||||
|
||||
if(NULL == (sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
|
||||
if (!(sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
|
||||
{
|
||||
LOGE(" ## initInboundGroupSessionWithSessionKeyJni(): failure - invalid inbound group session instance");
|
||||
}
|
||||
else if(0 == aSessionKey)
|
||||
else if (!aSessionKey)
|
||||
{
|
||||
LOGE(" ## initInboundGroupSessionWithSessionKeyJni(): failure - invalid aSessionKey");
|
||||
}
|
||||
else if(NULL == (sessionKeyPtr = (const uint8_t *)env->GetStringUTFChars(aSessionKey, 0)))
|
||||
else if (!(sessionKeyPtr = (const uint8_t *)env->GetStringUTFChars(aSessionKey, 0)))
|
||||
{
|
||||
LOGE(" ## initInboundSessionFromIdKeyJni(): failure - session key JNI allocation OOM");
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSes
|
|||
}
|
||||
|
||||
// free local alloc
|
||||
if(NULL!= sessionKeyPtr)
|
||||
if (sessionKeyPtr)
|
||||
{
|
||||
env->ReleaseStringUTFChars(aSessionKey, (const char*)sessionKeyPtr);
|
||||
}
|
||||
|
@ -140,12 +140,11 @@ JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSes
|
|||
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz)
|
||||
{
|
||||
OlmInboundGroupSession *sessionPtr = NULL;
|
||||
uint8_t *sessionIdPtr = NULL;
|
||||
jstring returnValueStr=0;
|
||||
|
||||
LOGD("## sessionIdentifierJni(): inbound group session IN");
|
||||
|
||||
if(NULL == (sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
|
||||
if (!(sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
|
||||
{
|
||||
LOGE(" ## sessionIdentifierJni(): failure - invalid inbound group session instance");
|
||||
}
|
||||
|
@ -155,13 +154,16 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEn
|
|||
size_t lengthSessionId = olm_inbound_group_session_id_length(sessionPtr);
|
||||
LOGD(" ## sessionIdentifierJni(): inbound group session lengthSessionId=%lu",static_cast<long unsigned int>(lengthSessionId));
|
||||
|
||||
if(NULL == (sessionIdPtr = (uint8_t*)malloc((lengthSessionId+1)*sizeof(uint8_t))))
|
||||
uint8_t *sessionIdPtr = (uint8_t*)malloc((lengthSessionId+1)*sizeof(uint8_t));
|
||||
|
||||
if (!sessionIdPtr)
|
||||
{
|
||||
LOGE(" ## sessionIdentifierJni(): failure - inbound group session identifier allocation OOM");
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t result = olm_inbound_group_session_id(sessionPtr, sessionIdPtr, lengthSessionId);
|
||||
|
||||
if (result == olm_error())
|
||||
{
|
||||
LOGE(" ## sessionIdentifierJni(): failure - get inbound group session identifier failure Msg=%s",(const char *)olm_inbound_group_session_last_error(sessionPtr));
|
||||
|
|
|
@ -113,6 +113,7 @@ bool setRandomInBuffer(JNIEnv *env, uint8_t **aBuffer2Ptr, size_t aRandomSize)
|
|||
jlong getInstanceId(JNIEnv* aJniEnv, jobject aJavaObject, const char *aCallingClass)
|
||||
{
|
||||
jlong instanceId = 0;
|
||||
|
||||
if (aJniEnv)
|
||||
{
|
||||
jclass requiredClass = aJniEnv->FindClass(aCallingClass);
|
||||
|
|
|
@ -26,11 +26,11 @@ using namespace AndroidOlmSdk;
|
|||
*/
|
||||
JNIEXPORT void OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz)
|
||||
{
|
||||
OlmOutboundGroupSession* sessionPtr = NULL;
|
||||
|
||||
LOGD("## releaseSessionJni(): OutBound group session IN");
|
||||
|
||||
if(NULL == (sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
|
||||
OlmOutboundGroupSession* sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz);
|
||||
|
||||
if (!sessionPtr)
|
||||
{
|
||||
LOGE(" ## releaseSessionJni(): failure - invalid outbound group session instance");
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ JNIEXPORT jlong OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv
|
|||
{
|
||||
LOGE(" ## createNewSessionJni(): failure - outbound group session size = 0");
|
||||
}
|
||||
else if(NULL != (sessionPtr=(OlmOutboundGroupSession*)malloc(sessionSize)))
|
||||
else if (!(sessionPtr = (OlmOutboundGroupSession*)malloc(sessionSize)))
|
||||
{
|
||||
sessionPtr = olm_outbound_group_session(sessionPtr);
|
||||
LOGD(" ## createNewSessionJni(): success - outbound group session size=%lu",static_cast<long unsigned int>(sessionSize));
|
||||
|
@ -89,12 +89,12 @@ JNIEXPORT jlong OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv
|
|||
JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(JNIEnv *env, jobject thiz)
|
||||
{
|
||||
jint retCode = ERROR_CODE_KO;
|
||||
OlmOutboundGroupSession *sessionPtr = NULL;
|
||||
uint8_t *randomBuffPtr = NULL;
|
||||
|
||||
LOGD("## initOutboundGroupSessionJni(): IN");
|
||||
|
||||
if(NULL == (sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
|
||||
OlmOutboundGroupSession *sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz);
|
||||
|
||||
if (!sessionPtr)
|
||||
{
|
||||
LOGE(" ## initOutboundGroupSessionJni(): failure - invalid outbound group session instance");
|
||||
}
|
||||
|
@ -102,7 +102,10 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(
|
|||
{
|
||||
// compute random buffer
|
||||
size_t randomLength = olm_init_outbound_group_session_random_length(sessionPtr);
|
||||
uint8_t *randomBuffPtr = NULL;
|
||||
|
||||
LOGW(" ## initOutboundGroupSessionJni(): randomLength=%lu",static_cast<long unsigned int>(randomLength));
|
||||
|
||||
if ((0 != randomLength) && !setRandomInBuffer(env, &randomBuffPtr, randomLength))
|
||||
{
|
||||
LOGE(" ## initOutboundGroupSessionJni(): failure - random buffer init");
|
||||
|
@ -115,6 +118,7 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(
|
|||
}
|
||||
|
||||
size_t sessionResult = olm_init_outbound_group_session(sessionPtr, randomBuffPtr, randomLength);
|
||||
|
||||
if (sessionResult == olm_error()) {
|
||||
LOGE(" ## initOutboundGroupSessionJni(): failure - init outbound session creation Msg=%s",(const char *)olm_outbound_group_session_last_error(sessionPtr));
|
||||
}
|
||||
|
@ -123,13 +127,10 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(
|
|||
retCode = ERROR_CODE_OK;
|
||||
LOGD(" ## initOutboundGroupSessionJni(): success - result=%lu", static_cast<long unsigned int>(sessionResult));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(NULL != randomBuffPtr)
|
||||
{
|
||||
free(randomBuffPtr);
|
||||
}
|
||||
}
|
||||
|
||||
return retCode;
|
||||
}
|
||||
|
@ -139,13 +140,11 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(
|
|||
*/
|
||||
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz)
|
||||
{
|
||||
OlmOutboundGroupSession *sessionPtr = NULL;
|
||||
uint8_t *sessionIdPtr = NULL;
|
||||
LOGD("## sessionIdentifierJni(): outbound group session IN");
|
||||
OlmOutboundGroupSession *sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz);
|
||||
jstring returnValueStr=0;
|
||||
|
||||
LOGD("## sessionIdentifierJni(): outbound group session IN");
|
||||
|
||||
if(NULL == (sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
|
||||
if (!sessionPtr)
|
||||
{
|
||||
LOGE(" ## sessionIdentifierJni(): failure - invalid outbound group session instance");
|
||||
}
|
||||
|
@ -155,13 +154,16 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIE
|
|||
size_t lengthSessionId = olm_outbound_group_session_id_length(sessionPtr);
|
||||
LOGD(" ## sessionIdentifierJni(): outbound group session lengthSessionId=%lu",static_cast<long unsigned int>(lengthSessionId));
|
||||
|
||||
if(NULL == (sessionIdPtr = (uint8_t*)malloc((lengthSessionId+1)*sizeof(uint8_t))))
|
||||
uint8_t *sessionIdPtr = (uint8_t*)malloc((lengthSessionId+1)*sizeof(uint8_t));
|
||||
|
||||
if (!sessionIdPtr)
|
||||
{
|
||||
LOGE(" ## sessionIdentifierJni(): failure - outbound identifier allocation OOM");
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t result = olm_outbound_group_session_id(sessionPtr, sessionIdPtr, lengthSessionId);
|
||||
|
||||
if (result == olm_error())
|
||||
{
|
||||
LOGE(" ## sessionIdentifierJni(): failure - outbound group session identifier failure Msg=%s",reinterpret_cast<const char*>(olm_outbound_group_session_last_error(sessionPtr)));
|
||||
|
@ -196,7 +198,7 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(messageIndexJni)(JNIEnv *env,
|
|||
|
||||
LOGD("## messageIndexJni(): IN");
|
||||
|
||||
if(NULL == (sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
|
||||
if (!(sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
|
||||
{
|
||||
LOGE(" ## messageIndexJni(): failure - invalid outbound group session instance");
|
||||
}
|
||||
|
@ -204,24 +206,22 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(messageIndexJni)(JNIEnv *env,
|
|||
{
|
||||
indexRetValue = static_cast<jint>(olm_outbound_group_session_message_index(sessionPtr));
|
||||
}
|
||||
|
||||
LOGD(" ## messageIndexJni(): success - index=%d",indexRetValue);
|
||||
|
||||
return indexRetValue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the base64-encoded current ratchet key for this session.<br>
|
||||
*/
|
||||
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *env, jobject thiz)
|
||||
{
|
||||
OlmOutboundGroupSession *sessionPtr = NULL;
|
||||
uint8_t *sessionKeyPtr = NULL;
|
||||
LOGD("## sessionKeyJni(): outbound group session IN");
|
||||
OlmOutboundGroupSession *sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz);
|
||||
jstring returnValueStr = 0;
|
||||
|
||||
LOGD("## sessionKeyJni(): outbound group session IN");
|
||||
|
||||
if(NULL == (sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
|
||||
if (!sessionPtr)
|
||||
{
|
||||
LOGE(" ## sessionKeyJni(): failure - invalid outbound group session instance");
|
||||
}
|
||||
|
@ -231,13 +231,16 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *env
|
|||
size_t sessionKeyLength = olm_outbound_group_session_key_length(sessionPtr);
|
||||
LOGD(" ## sessionKeyJni(): sessionKeyLength=%lu",static_cast<long unsigned int>(sessionKeyLength));
|
||||
|
||||
if(NULL == (sessionKeyPtr = (uint8_t*)malloc((sessionKeyLength+1)*sizeof(uint8_t))))
|
||||
uint8_t *sessionKeyPtr = (uint8_t*)malloc((sessionKeyLength+1)*sizeof(uint8_t));
|
||||
|
||||
if (!sessionKeyPtr)
|
||||
{
|
||||
LOGE(" ## sessionKeyJni(): failure - session key allocation OOM");
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t result = olm_outbound_group_session_key(sessionPtr, sessionKeyPtr, sessionKeyLength);
|
||||
|
||||
if (result == olm_error())
|
||||
{
|
||||
LOGE(" ## sessionKeyJni(): failure - session key failure Msg=%s",(const char *)olm_outbound_group_session_last_error(sessionPtr));
|
||||
|
@ -261,22 +264,21 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *env
|
|||
|
||||
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz, jstring aClearMsg)
|
||||
{
|
||||
LOGD("## encryptMessageJni(): IN");
|
||||
|
||||
jstring encryptedMsgRetValue = 0;
|
||||
OlmOutboundGroupSession *sessionPtr = NULL;
|
||||
const char *clearMsgPtr = NULL;
|
||||
uint8_t *encryptedMsgPtr = NULL;
|
||||
|
||||
LOGD("## encryptMessageJni(): IN");
|
||||
|
||||
if(NULL == (sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
|
||||
if (!(sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
|
||||
{
|
||||
LOGE(" ## encryptMessageJni(): failure - invalid outbound group session ptr=NULL");
|
||||
}
|
||||
else if(0 == aClearMsg)
|
||||
else if (!aClearMsg)
|
||||
{
|
||||
LOGE(" ## encryptMessageJni(): failure - invalid clear message");
|
||||
}
|
||||
else if(0 == (clearMsgPtr = env->GetStringUTFChars(aClearMsg, 0)))
|
||||
else if (!(clearMsgPtr = env->GetStringUTFChars(aClearMsg, 0)))
|
||||
{
|
||||
LOGE(" ## encryptMessageJni(): failure - clear message JNI allocation OOM");
|
||||
}
|
||||
|
@ -288,7 +290,9 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv
|
|||
|
||||
// compute max encrypted length
|
||||
size_t encryptedMsgLength = olm_group_encrypt_message_length(sessionPtr,clearMsgLength);
|
||||
if(NULL == (encryptedMsgPtr = (uint8_t*)malloc((encryptedMsgLength+1)*sizeof(uint8_t))))
|
||||
uint8_t *encryptedMsgPtr = (uint8_t*)malloc((encryptedMsgLength+1)*sizeof(uint8_t));
|
||||
|
||||
if (!encryptedMsgPtr)
|
||||
{
|
||||
LOGE(" ## encryptMessageJni(): failure - encryptedMsgPtr buffer OOM");
|
||||
}
|
||||
|
@ -313,20 +317,17 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv
|
|||
LOGD(" ## encryptMessageJni(): encrypted returnedLg=%lu plainTextMsgPtr=%s",static_cast<long unsigned int>(encryptedLength), reinterpret_cast<char*>(encryptedMsgPtr));
|
||||
encryptedMsgRetValue = env->NewStringUTF((const char*)encryptedMsgPtr);
|
||||
}
|
||||
|
||||
free(encryptedMsgPtr);
|
||||
}
|
||||
}
|
||||
|
||||
// free alloc
|
||||
if(NULL != clearMsgPtr)
|
||||
if (clearMsgPtr)
|
||||
{
|
||||
env->ReleaseStringUTFChars(aClearMsg, clearMsgPtr);
|
||||
}
|
||||
|
||||
if(NULL != encryptedMsgPtr)
|
||||
{
|
||||
free(encryptedMsgPtr);
|
||||
}
|
||||
|
||||
return encryptedMsgRetValue;
|
||||
}
|
||||
|
||||
|
@ -344,32 +345,31 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(J
|
|||
jmethodID errorMsgMethodId = 0;
|
||||
jstring errorJstring = 0;
|
||||
const char *keyPtr = NULL;
|
||||
void *pickledPtr = NULL;
|
||||
OlmOutboundGroupSession* sessionPtr = NULL;
|
||||
|
||||
LOGD("## outbound group session serializeDataWithKeyJni(): IN");
|
||||
|
||||
if(NULL == (sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
|
||||
if (!(sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
|
||||
{
|
||||
LOGE(" ## serializeDataWithKeyJni(): failure - invalid session ptr");
|
||||
}
|
||||
else if(0 == aKey)
|
||||
else if (!aKey)
|
||||
{
|
||||
LOGE(" ## serializeDataWithKeyJni(): failure - invalid key");
|
||||
}
|
||||
else if(0 == aErrorMsg)
|
||||
else if (!aErrorMsg)
|
||||
{
|
||||
LOGE(" ## serializeDataWithKeyJni(): failure - invalid error object");
|
||||
}
|
||||
else if(0 == (errorMsgJClass = env->GetObjectClass(aErrorMsg)))
|
||||
else if (!(errorMsgJClass = env->GetObjectClass(aErrorMsg)))
|
||||
{
|
||||
LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error class");
|
||||
}
|
||||
else if(0 == (errorMsgMethodId = env->GetMethodID(errorMsgJClass, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;")))
|
||||
else if (!(errorMsgMethodId = env->GetMethodID(errorMsgJClass, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;")))
|
||||
{
|
||||
LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error method ID");
|
||||
}
|
||||
else if(NULL == (keyPtr = env->GetStringUTFChars(aKey, 0)))
|
||||
else if (!(keyPtr = env->GetStringUTFChars(aKey, 0)))
|
||||
{
|
||||
LOGE(" ## serializeDataWithKeyJni(): failure - keyPtr JNI allocation OOM");
|
||||
}
|
||||
|
@ -380,7 +380,9 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(J
|
|||
LOGD(" ## serializeDataWithKeyJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
|
||||
LOGD(" ## serializeDataWithKeyJni(): key=%s",(char const *)keyPtr);
|
||||
|
||||
if(NULL == (pickledPtr = (void*)malloc((pickledLength+1)*sizeof(uint8_t))))
|
||||
void *pickledPtr = malloc((pickledLength+1)*sizeof(uint8_t));
|
||||
|
||||
if(!pickledPtr)
|
||||
{
|
||||
LOGE(" ## serializeDataWithKeyJni(): failure - pickledPtr buffer OOM");
|
||||
}
|
||||
|
@ -396,7 +398,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(J
|
|||
const char *errorMsgPtr = olm_outbound_group_session_last_error(sessionPtr);
|
||||
LOGE(" ## serializeDataWithKeyJni(): failure - olm_pickle_outbound_group_session() Msg=%s",errorMsgPtr);
|
||||
|
||||
if(0 != (errorJstring = env->NewStringUTF(errorMsgPtr)))
|
||||
if (!(errorJstring = env->NewStringUTF(errorMsgPtr)))
|
||||
{
|
||||
env->CallObjectMethod(aErrorMsg, errorMsgMethodId, errorJstring);
|
||||
}
|
||||
|
@ -409,19 +411,16 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(J
|
|||
LOGD(" ## serializeDataWithKeyJni(): success - result=%lu pickled=%s", static_cast<long unsigned int>(result), static_cast<char*>(pickledPtr));
|
||||
}
|
||||
}
|
||||
|
||||
free(pickledPtr);
|
||||
}
|
||||
|
||||
// free alloc
|
||||
if(NULL != keyPtr)
|
||||
if (keyPtr)
|
||||
{
|
||||
env->ReleaseStringUTFChars(aKey, keyPtr);
|
||||
}
|
||||
|
||||
if(NULL != pickledPtr)
|
||||
{
|
||||
free(pickledPtr);
|
||||
}
|
||||
|
||||
return pickledDataRetValue;
|
||||
}
|
||||
|
||||
|
@ -435,23 +434,23 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initWithSerializedDataJni)
|
|||
|
||||
LOGD("## initWithSerializedDataJni(): IN");
|
||||
|
||||
if(NULL == (sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
|
||||
if (!(sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
|
||||
{
|
||||
LOGE(" ## initWithSerializedDataJni(): failure - session failure OOM");
|
||||
}
|
||||
else if(0 == aKey)
|
||||
else if (!aKey)
|
||||
{
|
||||
LOGE(" ## initWithSerializedDataJni(): failure - invalid key");
|
||||
}
|
||||
else if(0 == aSerializedData)
|
||||
else if (!aSerializedData)
|
||||
{
|
||||
LOGE(" ## initWithSerializedDataJni(): failure - serialized data");
|
||||
}
|
||||
else if(NULL == (keyPtr = env->GetStringUTFChars(aKey, 0)))
|
||||
else if (!(keyPtr = env->GetStringUTFChars(aKey, 0)))
|
||||
{
|
||||
LOGE(" ## initWithSerializedDataJni(): failure - keyPtr JNI allocation OOM");
|
||||
}
|
||||
else if(NULL == (pickledPtr = env->GetStringUTFChars(aSerializedData, 0)))
|
||||
else if (!(pickledPtr = env->GetStringUTFChars(aSerializedData, 0)))
|
||||
{
|
||||
LOGE(" ## initWithSerializedDataJni(): failure - pickledPtr JNI allocation OOM");
|
||||
}
|
||||
|
@ -481,12 +480,12 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initWithSerializedDataJni)
|
|||
}
|
||||
|
||||
// free alloc
|
||||
if(NULL != keyPtr)
|
||||
if (keyPtr)
|
||||
{
|
||||
env->ReleaseStringUTFChars(aKey, keyPtr);
|
||||
}
|
||||
|
||||
if(NULL != pickledPtr)
|
||||
if (pickledPtr)
|
||||
{
|
||||
env->ReleaseStringUTFChars(aSerializedData, pickledPtr);
|
||||
}
|
||||
|
|
|
@ -26,11 +26,12 @@ using namespace AndroidOlmSdk;
|
|||
**/
|
||||
OlmSession* initializeSessionMemory()
|
||||
{
|
||||
OlmSession* sessionPtr = NULL;
|
||||
size_t sessionSize = olm_session_size();
|
||||
OlmSession* sessionPtr = (OlmSession*)malloc(sessionSize);
|
||||
|
||||
if(NULL != (sessionPtr=(OlmSession*)malloc(sessionSize)))
|
||||
{ // init session object
|
||||
if (sessionPtr)
|
||||
{
|
||||
// init session object
|
||||
sessionPtr = olm_session(sessionPtr);
|
||||
LOGD("## initializeSessionMemory(): success - OLM session size=%lu",static_cast<long unsigned int>(sessionSize));
|
||||
}
|
||||
|
@ -53,11 +54,10 @@ JNIEXPORT jlong OLM_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *env, jobject t
|
|||
|
||||
JNIEXPORT void OLM_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz)
|
||||
{
|
||||
OlmSession* sessionPtr = NULL;
|
||||
|
||||
LOGD("## releaseSessionJni(): IN");
|
||||
OlmSession* sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz);
|
||||
|
||||
if(NULL == (sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
||||
if (!sessionPtr)
|
||||
{
|
||||
LOGE("## releaseSessionJni(): failure - invalid Session ptr=NULL");
|
||||
}
|
||||
|
@ -78,12 +78,12 @@ JNIEXPORT void OLM_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz
|
|||
**/
|
||||
JNIEXPORT jlong OLM_SESSION_FUNC_DEF(initNewSessionJni)(JNIEnv *env, jobject thiz)
|
||||
{
|
||||
OlmSession* sessionPtr = NULL;
|
||||
|
||||
LOGD("## initNewSessionJni(): OlmSession IN");
|
||||
|
||||
OlmSession* sessionPtr = initializeSessionMemory();
|
||||
|
||||
// init account memory allocation
|
||||
if(NULL == (sessionPtr = initializeSessionMemory()))
|
||||
if (!sessionPtr)
|
||||
{
|
||||
LOGE(" ## initNewSessionJni(): failure - init session OOM");
|
||||
}
|
||||
|
@ -112,38 +112,41 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(initOutboundSessionJni)(JNIEnv *env, jobject
|
|||
jint retCode = ERROR_CODE_KO;
|
||||
OlmSession* sessionPtr = NULL;
|
||||
OlmAccount* accountPtr = NULL;
|
||||
const char* theirIdentityKeyPtr = NULL;
|
||||
const char* theirOneTimeKeyPtr = NULL;
|
||||
uint8_t *randomBuffPtr = NULL;
|
||||
size_t sessionResult;
|
||||
|
||||
if(NULL == (sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
||||
if (!(sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
||||
{
|
||||
LOGE("## initOutboundSessionJni(): failure - invalid Session ptr=NULL");
|
||||
}
|
||||
else if(NULL == (accountPtr = (OlmAccount*)aOlmAccountId))
|
||||
else if (!(accountPtr = (OlmAccount*)aOlmAccountId))
|
||||
{
|
||||
LOGE("## initOutboundSessionJni(): failure - invalid Account ptr=NULL");
|
||||
}
|
||||
else if((0==aTheirIdentityKey) || (0==aTheirOneTimeKey))
|
||||
else if (!aTheirIdentityKey || !aTheirOneTimeKey)
|
||||
{
|
||||
LOGE("## initOutboundSessionJni(): failure - invalid keys");
|
||||
}
|
||||
else
|
||||
{ // allocate random buffer
|
||||
{
|
||||
size_t randomSize = olm_create_outbound_session_random_length(sessionPtr);
|
||||
uint8_t *randomBuffPtr = NULL;
|
||||
|
||||
LOGD("## initOutboundSessionJni(): randomSize=%lu",static_cast<long unsigned int>(randomSize));
|
||||
|
||||
if ( (0 != randomSize) && !setRandomInBuffer(env, &randomBuffPtr, randomSize))
|
||||
{
|
||||
LOGE("## initOutboundSessionJni(): failure - random buffer init");
|
||||
}
|
||||
else
|
||||
{ // convert identity & one time keys to C strings
|
||||
if(NULL == (theirIdentityKeyPtr = env->GetStringUTFChars(aTheirIdentityKey, 0)))
|
||||
{
|
||||
const char* theirIdentityKeyPtr = NULL;
|
||||
const char* theirOneTimeKeyPtr = NULL;
|
||||
|
||||
// convert identity & one time keys to C strings
|
||||
if (!(theirIdentityKeyPtr = env->GetStringUTFChars(aTheirIdentityKey, 0)))
|
||||
{
|
||||
LOGE("## initOutboundSessionJni(): failure - identityKey JNI allocation OOM");
|
||||
}
|
||||
else if(NULL == (theirOneTimeKeyPtr = env->GetStringUTFChars(aTheirOneTimeKey, 0)))
|
||||
else if (!(theirOneTimeKeyPtr = env->GetStringUTFChars(aTheirOneTimeKey, 0)))
|
||||
{
|
||||
LOGE("## initOutboundSessionJni(): failure - one time Key JNI allocation OOM");
|
||||
}
|
||||
|
@ -153,7 +156,7 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(initOutboundSessionJni)(JNIEnv *env, jobject
|
|||
size_t theirOneTimeKeyLength = (size_t)env->GetStringUTFLength(aTheirOneTimeKey);
|
||||
LOGD("## initOutboundSessionJni(): identityKey=%s oneTimeKey=%s",theirIdentityKeyPtr,theirOneTimeKeyPtr);
|
||||
|
||||
sessionResult = olm_create_outbound_session(sessionPtr,
|
||||
size_t sessionResult = olm_create_outbound_session(sessionPtr,
|
||||
accountPtr,
|
||||
theirIdentityKeyPtr,
|
||||
theirIdentityKeyLength,
|
||||
|
@ -170,25 +173,24 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(initOutboundSessionJni)(JNIEnv *env, jobject
|
|||
LOGD("## initOutboundSessionJni(): success - result=%lu", static_cast<long unsigned int>(sessionResult));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// **** free mem alloc ***
|
||||
if(NULL!= randomBuffPtr)
|
||||
{
|
||||
free(randomBuffPtr);
|
||||
}
|
||||
|
||||
if(NULL!= theirIdentityKeyPtr)
|
||||
if (theirIdentityKeyPtr)
|
||||
{
|
||||
env->ReleaseStringUTFChars(aTheirIdentityKey, theirIdentityKeyPtr);
|
||||
}
|
||||
|
||||
if(NULL!= theirOneTimeKeyPtr)
|
||||
if (theirOneTimeKeyPtr)
|
||||
{
|
||||
env->ReleaseStringUTFChars(aTheirOneTimeKey, theirOneTimeKeyPtr);
|
||||
}
|
||||
|
||||
if (randomBuffPtr)
|
||||
{
|
||||
free(randomBuffPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return retCode;
|
||||
}
|
||||
|
||||
|
@ -208,24 +210,25 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(initInboundSessionJni)(JNIEnv *env, jobject
|
|||
jint retCode = ERROR_CODE_KO;
|
||||
OlmSession *sessionPtr = NULL;
|
||||
OlmAccount *accountPtr = NULL;
|
||||
const char *messagePtr = NULL;
|
||||
size_t sessionResult;
|
||||
|
||||
if(NULL == (sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
||||
if (!(sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
||||
{
|
||||
LOGE("## initInboundSessionJni(): failure - invalid Session ptr=NULL");
|
||||
}
|
||||
else if(NULL == (accountPtr = (OlmAccount*)aOlmAccountId))
|
||||
else if (!(accountPtr = (OlmAccount*)aOlmAccountId))
|
||||
{
|
||||
LOGE("## initInboundSessionJni(): failure - invalid Account ptr=NULL");
|
||||
}
|
||||
else if(0==aOneTimeKeyMsg)
|
||||
else if (!aOneTimeKeyMsg)
|
||||
{
|
||||
LOGE("## initInboundSessionJni(): failure - invalid message");
|
||||
}
|
||||
else
|
||||
{ // convert message to C strings
|
||||
if(NULL == (messagePtr = env->GetStringUTFChars(aOneTimeKeyMsg, 0)))
|
||||
{
|
||||
const char *messagePtr = env->GetStringUTFChars(aOneTimeKeyMsg, 0);
|
||||
|
||||
if (!messagePtr)
|
||||
{
|
||||
LOGE("## initInboundSessionJni(): failure - message JNI allocation OOM");
|
||||
}
|
||||
|
@ -235,7 +238,9 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(initInboundSessionJni)(JNIEnv *env, jobject
|
|||
LOGD("## initInboundSessionJni(): messageLength=%lu message=%s", static_cast<long unsigned int>(messageLength), messagePtr);
|
||||
|
||||
sessionResult = olm_create_inbound_session(sessionPtr, accountPtr, (void*)messagePtr , messageLength);
|
||||
if(sessionResult == olm_error()) {
|
||||
|
||||
if (sessionResult == olm_error())
|
||||
{
|
||||
LOGE("## initInboundSessionJni(): failure - init inbound session creation Msg=%s",(const char *)olm_session_last_error(sessionPtr));
|
||||
}
|
||||
else
|
||||
|
@ -268,27 +273,27 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(initInboundSessionFromIdKeyJni)(JNIEnv *env,
|
|||
const char *theirIdentityKeyPtr = NULL;
|
||||
size_t sessionResult;
|
||||
|
||||
if(NULL == (sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
||||
if (!(sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
||||
{
|
||||
LOGE("## initInboundSessionFromIdKeyJni(): failure - invalid Session ptr=NULL");
|
||||
}
|
||||
else if(NULL == (accountPtr = (OlmAccount*)aOlmAccountId))
|
||||
else if (!(accountPtr = (OlmAccount*)aOlmAccountId))
|
||||
{
|
||||
LOGE("## initInboundSessionFromIdKeyJni(): failure - invalid Account ptr=NULL");
|
||||
}
|
||||
else if(0 == aTheirIdentityKey)
|
||||
else if (!aTheirIdentityKey)
|
||||
{
|
||||
LOGE("## initInboundSessionFromIdKeyJni(): failure - invalid theirIdentityKey");
|
||||
}
|
||||
else if(0==aOneTimeKeyMsg)
|
||||
else if (!aOneTimeKeyMsg)
|
||||
{
|
||||
LOGE("## initInboundSessionJni(): failure - invalid one time key message");
|
||||
}
|
||||
else if(NULL == (messagePtr = env->GetStringUTFChars(aOneTimeKeyMsg, 0)))
|
||||
else if (!(messagePtr = env->GetStringUTFChars(aOneTimeKeyMsg, 0)))
|
||||
{
|
||||
LOGE("## initInboundSessionFromIdKeyJni(): failure - message JNI allocation OOM");
|
||||
}
|
||||
else if(NULL == (theirIdentityKeyPtr = env->GetStringUTFChars(aTheirIdentityKey, 0)))
|
||||
else if(!(theirIdentityKeyPtr = env->GetStringUTFChars(aTheirIdentityKey, 0)))
|
||||
{
|
||||
LOGE("## initInboundSessionFromIdKeyJni(): failure - theirIdentityKey JNI allocation OOM");
|
||||
}
|
||||
|
@ -300,7 +305,8 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(initInboundSessionFromIdKeyJni)(JNIEnv *env,
|
|||
LOGD("## initInboundSessionFromIdKeyJni(): message=%s messageLength=%lu",messagePtr,static_cast<long unsigned int>(messageLength));
|
||||
|
||||
sessionResult = olm_create_inbound_session_from(sessionPtr, accountPtr, theirIdentityKeyPtr, theirIdentityKeyLength, (void*)messagePtr , messageLength);
|
||||
if(sessionResult == olm_error()) {
|
||||
if (sessionResult == olm_error())
|
||||
{
|
||||
LOGE("## initInboundSessionFromIdKeyJni(): failure - init inbound session creation Msg=%s",(const char *)olm_session_last_error(sessionPtr));
|
||||
}
|
||||
else
|
||||
|
@ -311,11 +317,12 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(initInboundSessionFromIdKeyJni)(JNIEnv *env,
|
|||
}
|
||||
|
||||
// free local alloc
|
||||
if(NULL!= messagePtr)
|
||||
if (messagePtr)
|
||||
{
|
||||
env->ReleaseStringUTFChars(aOneTimeKeyMsg, messagePtr);
|
||||
}
|
||||
if(NULL!= theirIdentityKeyPtr)
|
||||
|
||||
if (theirIdentityKeyPtr)
|
||||
{
|
||||
env->ReleaseStringUTFChars(aTheirIdentityKey, theirIdentityKeyPtr);
|
||||
}
|
||||
|
@ -335,15 +342,15 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(matchesInboundSessionJni)(JNIEnv *env, jobje
|
|||
OlmSession *sessionPtr = NULL;
|
||||
const char *messagePtr = NULL;
|
||||
|
||||
if(NULL == (sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
||||
if (!(sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
||||
{
|
||||
LOGE("## matchesInboundSessionJni(): failure - invalid Session ptr=NULL");
|
||||
}
|
||||
else if(0==aOneTimeKeyMsg)
|
||||
else if (!aOneTimeKeyMsg)
|
||||
{
|
||||
LOGE("## matchesInboundSessionJni(): failure - invalid one time key message");
|
||||
}
|
||||
else if(NULL == (messagePtr = env->GetStringUTFChars(aOneTimeKeyMsg, 0)))
|
||||
else if (!(messagePtr = env->GetStringUTFChars(aOneTimeKeyMsg, 0)))
|
||||
{
|
||||
LOGE("## matchesInboundSessionJni(): failure - one time key JNI allocation OOM");
|
||||
}
|
||||
|
@ -365,7 +372,7 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(matchesInboundSessionJni)(JNIEnv *env, jobje
|
|||
}
|
||||
|
||||
// free local alloc
|
||||
if(NULL!= messagePtr)
|
||||
if (messagePtr)
|
||||
{
|
||||
env->ReleaseStringUTFChars(aOneTimeKeyMsg, messagePtr);
|
||||
}
|
||||
|
@ -388,23 +395,23 @@ JNIEXPORT jint JNICALL OLM_SESSION_FUNC_DEF(matchesInboundSessionFromIdKeyJni)(J
|
|||
const char *messagePtr = NULL;
|
||||
const char *theirIdentityKeyPtr = NULL;
|
||||
|
||||
if(NULL == (sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
||||
if (!(sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
||||
{
|
||||
LOGE("## matchesInboundSessionFromIdKeyJni(): failure - invalid Session ptr=NULL");
|
||||
}
|
||||
else if(0 == aTheirIdentityKey)
|
||||
else if (!aTheirIdentityKey)
|
||||
{
|
||||
LOGE("## matchesInboundSessionFromIdKeyJni(): failure - invalid theirIdentityKey");
|
||||
}
|
||||
else if(NULL == (theirIdentityKeyPtr = env->GetStringUTFChars(aTheirIdentityKey, 0)))
|
||||
else if (!(theirIdentityKeyPtr = env->GetStringUTFChars(aTheirIdentityKey, 0)))
|
||||
{
|
||||
LOGE("## matchesInboundSessionFromIdKeyJni(): failure - theirIdentityKey JNI allocation OOM");
|
||||
}
|
||||
else if(0==aOneTimeKeyMsg)
|
||||
else if (!aOneTimeKeyMsg)
|
||||
{
|
||||
LOGE("## matchesInboundSessionFromIdKeyJni(): failure - invalid one time key message");
|
||||
}
|
||||
else if(NULL == (messagePtr = env->GetStringUTFChars(aOneTimeKeyMsg, 0)))
|
||||
else if (!(messagePtr = env->GetStringUTFChars(aOneTimeKeyMsg, 0)))
|
||||
{
|
||||
LOGE("## matchesInboundSessionFromIdKeyJni(): failure - one time key JNI allocation OOM");
|
||||
}
|
||||
|
@ -412,11 +419,12 @@ JNIEXPORT jint JNICALL OLM_SESSION_FUNC_DEF(matchesInboundSessionFromIdKeyJni)(J
|
|||
{
|
||||
size_t identityKeyLength = (size_t)env->GetStringUTFLength(aTheirIdentityKey);
|
||||
size_t messageLength = (size_t)env->GetStringUTFLength(aOneTimeKeyMsg);
|
||||
|
||||
size_t matchResult = olm_matches_inbound_session_from(sessionPtr, (void const *)theirIdentityKeyPtr, identityKeyLength, (void*)messagePtr , messageLength);
|
||||
|
||||
//if(matchResult == olm_error()) {
|
||||
// for now olm_matches_inbound_session() returns 1 when it succeeds, otherwise 1- or 0
|
||||
if(matchResult != 1) {
|
||||
if (matchResult != 1)
|
||||
{
|
||||
LOGE("## matchesInboundSessionFromIdKeyJni(): failure - no match Msg=%s",(const char *)olm_session_last_error(sessionPtr));
|
||||
}
|
||||
else
|
||||
|
@ -427,12 +435,12 @@ JNIEXPORT jint JNICALL OLM_SESSION_FUNC_DEF(matchesInboundSessionFromIdKeyJni)(J
|
|||
}
|
||||
|
||||
// free local alloc
|
||||
if(NULL!= theirIdentityKeyPtr)
|
||||
if (theirIdentityKeyPtr)
|
||||
{
|
||||
env->ReleaseStringUTFChars(aTheirIdentityKey, theirIdentityKeyPtr);
|
||||
}
|
||||
|
||||
if(NULL!= messagePtr)
|
||||
if (messagePtr)
|
||||
{
|
||||
env->ReleaseStringUTFChars(aOneTimeKeyMsg, messagePtr);
|
||||
}
|
||||
|
@ -452,39 +460,37 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz
|
|||
jint retCode = ERROR_CODE_KO;
|
||||
OlmSession *sessionPtr = NULL;
|
||||
const char *clearMsgPtr = NULL;
|
||||
uint8_t *randomBuffPtr = NULL;
|
||||
void *encryptedMsgPtr = NULL;
|
||||
jclass encryptedMsgJClass = 0;
|
||||
jfieldID encryptedMsgFieldId;
|
||||
jfieldID typeMsgFieldId;
|
||||
|
||||
LOGD("## encryptMessageJni(): IN ");
|
||||
|
||||
if(NULL == (sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
||||
if (!(sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
||||
{
|
||||
LOGE("## encryptMessageJni(): failure - invalid Session ptr=NULL");
|
||||
}
|
||||
else if(0 == aClearMsg)
|
||||
else if (!aClearMsg)
|
||||
{
|
||||
LOGE("## encryptMessageJni(): failure - invalid clear message");
|
||||
}
|
||||
else if(0 == aEncryptedMsg)
|
||||
else if (!aEncryptedMsg)
|
||||
{
|
||||
LOGE("## encryptMessageJni(): failure - invalid encrypted message");
|
||||
}
|
||||
else if(NULL == (clearMsgPtr = env->GetStringUTFChars(aClearMsg, 0)))
|
||||
else if (!(clearMsgPtr = env->GetStringUTFChars(aClearMsg, 0)))
|
||||
{
|
||||
LOGE("## encryptMessageJni(): failure - clear message JNI allocation OOM");
|
||||
}
|
||||
else if(0 == (encryptedMsgJClass = env->GetObjectClass(aEncryptedMsg)))
|
||||
else if (!(encryptedMsgJClass = env->GetObjectClass(aEncryptedMsg)))
|
||||
{
|
||||
LOGE("## encryptMessageJni(): failure - unable to get crypted message class");
|
||||
}
|
||||
else if(0 == (encryptedMsgFieldId = env->GetFieldID(encryptedMsgJClass,"mCipherText","Ljava/lang/String;")))
|
||||
else if (!(encryptedMsgFieldId = env->GetFieldID(encryptedMsgJClass,"mCipherText","Ljava/lang/String;")))
|
||||
{
|
||||
LOGE("## encryptMessageJni(): failure - unable to get message field");
|
||||
}
|
||||
else if(0 == (typeMsgFieldId = env->GetFieldID(encryptedMsgJClass,"mType","J")))
|
||||
else if (!(typeMsgFieldId = env->GetFieldID(encryptedMsgJClass,"mType","J")))
|
||||
{
|
||||
LOGE("## encryptMessageJni(): failure - unable to get message type field");
|
||||
}
|
||||
|
@ -492,12 +498,15 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz
|
|||
{
|
||||
// get message type
|
||||
size_t messageType = olm_encrypt_message_type(sessionPtr);
|
||||
uint8_t *randomBuffPtr = NULL;
|
||||
|
||||
// compute random buffer
|
||||
// Note: olm_encrypt_random_length() can return 0, which means
|
||||
// it just does not need new random data to encrypt a new message
|
||||
size_t randomLength = olm_encrypt_random_length(sessionPtr);
|
||||
|
||||
LOGD("## encryptMessageJni(): randomLength=%lu", static_cast<long unsigned int>(randomLength));
|
||||
|
||||
if ((0 != randomLength) && !setRandomInBuffer(env, &randomBuffPtr, randomLength))
|
||||
{
|
||||
LOGE("## encryptMessageJni(): failure - random buffer init");
|
||||
|
@ -507,7 +516,10 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz
|
|||
// alloc buffer for encrypted message
|
||||
size_t clearMsgLength = (size_t)env->GetStringUTFLength(aClearMsg);
|
||||
size_t encryptedMsgLength = olm_encrypt_message_length(sessionPtr, clearMsgLength);
|
||||
if(NULL == (encryptedMsgPtr = (void*)malloc((encryptedMsgLength+1)*sizeof(uint8_t))))
|
||||
|
||||
void *encryptedMsgPtr = malloc((encryptedMsgLength+1)*sizeof(uint8_t));
|
||||
|
||||
if (!encryptedMsgPtr)
|
||||
{
|
||||
LOGE("## encryptMessageJni(): failure - encryptedMsgPtr buffer OOM");
|
||||
}
|
||||
|
@ -546,30 +558,23 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz
|
|||
retCode = ERROR_CODE_OK;
|
||||
LOGD("## encryptMessageJni(): success - result=%lu Type=%lu utfLength=%lu encryptedMsg=%s", static_cast<long unsigned int>(result), static_cast<long unsigned int>(messageType), static_cast<long unsigned int>((size_t)env->GetStringUTFLength(encryptedJstring)), (const char*)encryptedMsgPtr);
|
||||
}
|
||||
|
||||
free(encryptedMsgPtr);
|
||||
}
|
||||
|
||||
free(randomBuffPtr);
|
||||
}
|
||||
}
|
||||
|
||||
// free alloc
|
||||
if(NULL != clearMsgPtr)
|
||||
if (clearMsgPtr)
|
||||
{
|
||||
env->ReleaseStringUTFChars(aClearMsg, clearMsgPtr);
|
||||
}
|
||||
|
||||
if(NULL != randomBuffPtr)
|
||||
{
|
||||
free(randomBuffPtr);
|
||||
}
|
||||
|
||||
if(NULL != encryptedMsgPtr)
|
||||
{
|
||||
free(encryptedMsgPtr);
|
||||
}
|
||||
|
||||
return retCode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Decrypt a message using the session.<br>
|
||||
* @param aEncryptedMsg message to decrypt
|
||||
|
@ -591,31 +596,31 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject t
|
|||
|
||||
LOGD("## decryptMessageJni(): IN - OlmSession");
|
||||
|
||||
if(NULL == (sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
||||
if (!(sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
||||
{
|
||||
LOGE("## decryptMessageJni(): failure - invalid Session ptr=NULL");
|
||||
}
|
||||
else if(0 == aEncryptedMsg)
|
||||
else if (!aEncryptedMsg)
|
||||
{
|
||||
LOGE("## decryptMessageJni(): failure - invalid encrypted message");
|
||||
}
|
||||
else if(0 == (encryptedMsgJClass = env->GetObjectClass(aEncryptedMsg)))
|
||||
else if (!(encryptedMsgJClass = env->GetObjectClass(aEncryptedMsg)))
|
||||
{
|
||||
LOGE("## decryptMessageJni(): failure - unable to get encrypted message class");
|
||||
}
|
||||
else if(0 == (encryptedMsgFieldId = env->GetFieldID(encryptedMsgJClass,"mCipherText","Ljava/lang/String;")))
|
||||
else if (!(encryptedMsgFieldId = env->GetFieldID(encryptedMsgJClass,"mCipherText","Ljava/lang/String;")))
|
||||
{
|
||||
LOGE("## decryptMessageJni(): failure - unable to get message field");
|
||||
}
|
||||
else if(0 == (typeMsgFieldId = env->GetFieldID(encryptedMsgJClass,"mType","J")))
|
||||
else if (!(typeMsgFieldId = env->GetFieldID(encryptedMsgJClass,"mType","J")))
|
||||
{
|
||||
LOGE("## decryptMessageJni(): failure - unable to get message type field");
|
||||
}
|
||||
else if(0 == (encryptedMsgJstring = (jstring)env->GetObjectField(aEncryptedMsg, encryptedMsgFieldId)))
|
||||
else if (!(encryptedMsgJstring = (jstring)env->GetObjectField(aEncryptedMsg, encryptedMsgFieldId)))
|
||||
{
|
||||
LOGE("## decryptMessageJni(): failure - JNI encrypted object ");
|
||||
}
|
||||
else if(0 == (encryptedMsgPtr = env->GetStringUTFChars(encryptedMsgJstring, 0)))
|
||||
else if (!(encryptedMsgPtr = env->GetStringUTFChars(encryptedMsgJstring, 0)))
|
||||
{
|
||||
LOGE("## decryptMessageJni(): failure - encrypted message JNI allocation OOM");
|
||||
}
|
||||
|
@ -689,17 +694,17 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject t
|
|||
}
|
||||
|
||||
// free alloc
|
||||
if(NULL != encryptedMsgPtr)
|
||||
if (encryptedMsgPtr)
|
||||
{
|
||||
env->ReleaseStringUTFChars(encryptedMsgJstring, encryptedMsgPtr);
|
||||
}
|
||||
|
||||
if(NULL != tempEncryptedPtr)
|
||||
if (tempEncryptedPtr)
|
||||
{
|
||||
free(tempEncryptedPtr);
|
||||
}
|
||||
|
||||
if(NULL != plainTextMsgPtr)
|
||||
if (plainTextMsgPtr)
|
||||
{
|
||||
free(plainTextMsgPtr);
|
||||
}
|
||||
|
@ -714,13 +719,13 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject t
|
|||
*/
|
||||
JNIEXPORT jstring OLM_SESSION_FUNC_DEF(getSessionIdentifierJni)(JNIEnv *env, jobject thiz)
|
||||
{
|
||||
OlmSession *sessionPtr = NULL;
|
||||
void *sessionIdPtr = NULL;
|
||||
jstring returnValueStr=0;
|
||||
|
||||
LOGD("## getSessionIdentifierJni(): IN ");
|
||||
|
||||
if(NULL == (sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
||||
OlmSession *sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz);
|
||||
|
||||
if (!sessionPtr)
|
||||
{
|
||||
LOGE("## getSessionIdentifierJni(): failure - invalid Session ptr=NULL");
|
||||
}
|
||||
|
@ -730,7 +735,9 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(getSessionIdentifierJni)(JNIEnv *env, job
|
|||
size_t lengthSessionId = olm_session_id_length(sessionPtr);
|
||||
LOGD("## getSessionIdentifierJni(): lengthSessionId=%lu",static_cast<long unsigned int>(lengthSessionId));
|
||||
|
||||
if(NULL == (sessionIdPtr = (void*)malloc((lengthSessionId+1)*sizeof(uint8_t))))
|
||||
void *sessionIdPtr = malloc((lengthSessionId+1)*sizeof(uint8_t));
|
||||
|
||||
if (!sessionIdPtr)
|
||||
{
|
||||
LOGE("## getSessionIdentifierJni(): failure - identifier allocation OOM");
|
||||
}
|
||||
|
@ -771,32 +778,31 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, job
|
|||
jmethodID errorMsgMethodId = 0;
|
||||
jstring errorJstring = 0;
|
||||
const char *keyPtr = NULL;
|
||||
void *pickledPtr = NULL;
|
||||
OlmSession* sessionPtr = NULL;
|
||||
|
||||
LOGD("## serializeDataWithKeyJni(): IN");
|
||||
|
||||
if(NULL == (sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
||||
if (!(sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
||||
{
|
||||
LOGE(" ## serializeDataWithKeyJni(): failure - invalid session ptr");
|
||||
}
|
||||
else if(0 == aKey)
|
||||
else if (!aKey)
|
||||
{
|
||||
LOGE(" ## serializeDataWithKeyJni(): failure - invalid key");
|
||||
}
|
||||
else if(0 == aErrorMsg)
|
||||
else if (!aErrorMsg)
|
||||
{
|
||||
LOGE(" ## serializeDataWithKeyJni(): failure - invalid error object");
|
||||
}
|
||||
else if(0 == (errorMsgJClass = env->GetObjectClass(aErrorMsg)))
|
||||
else if (!(errorMsgJClass = env->GetObjectClass(aErrorMsg)))
|
||||
{
|
||||
LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error class");
|
||||
}
|
||||
else if(0 == (errorMsgMethodId = env->GetMethodID(errorMsgJClass, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;")))
|
||||
else if (!(errorMsgMethodId = env->GetMethodID(errorMsgJClass, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;")))
|
||||
{
|
||||
LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error method ID");
|
||||
}
|
||||
else if(NULL == (keyPtr = env->GetStringUTFChars(aKey, 0)))
|
||||
else if (!(keyPtr = env->GetStringUTFChars(aKey, 0)))
|
||||
{
|
||||
LOGE(" ## serializeDataWithKeyJni(): failure - keyPtr JNI allocation OOM");
|
||||
}
|
||||
|
@ -807,7 +813,9 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, job
|
|||
LOGD(" ## serializeDataWithKeyJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
|
||||
LOGD(" ## serializeDataWithKeyJni(): key=%s",(char const *)keyPtr);
|
||||
|
||||
if(NULL == (pickledPtr = (void*)malloc((pickledLength+1)*sizeof(uint8_t))))
|
||||
void *pickledPtr = malloc((pickledLength+1)*sizeof(uint8_t));
|
||||
|
||||
if (!pickledPtr)
|
||||
{
|
||||
LOGE(" ## serializeDataWithKeyJni(): failure - pickledPtr buffer OOM");
|
||||
}
|
||||
|
@ -835,20 +843,17 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, job
|
|||
pickledDataRetValue = env->NewStringUTF((const char*)pickledPtr);
|
||||
LOGD(" ## serializeDataWithKeyJni(): success - result=%lu pickled=%s", static_cast<long unsigned int>(result), static_cast<char*>(pickledPtr));
|
||||
}
|
||||
|
||||
free(pickledPtr);
|
||||
}
|
||||
}
|
||||
|
||||
// free alloc
|
||||
if(NULL != keyPtr)
|
||||
if (keyPtr)
|
||||
{
|
||||
env->ReleaseStringUTFChars(aKey, keyPtr);
|
||||
}
|
||||
|
||||
if(NULL != pickledPtr)
|
||||
{
|
||||
free(pickledPtr);
|
||||
}
|
||||
|
||||
return pickledDataRetValue;
|
||||
}
|
||||
|
||||
|
@ -862,23 +867,23 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, j
|
|||
|
||||
LOGD("## initWithSerializedDataJni(): IN");
|
||||
|
||||
if(NULL == (sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
||||
if (!(sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
||||
{
|
||||
LOGE(" ## initWithSerializedDataJni(): failure - session failure OOM");
|
||||
}
|
||||
else if(0 == aKey)
|
||||
else if (!aKey)
|
||||
{
|
||||
LOGE(" ## initWithSerializedDataJni(): failure - invalid key");
|
||||
}
|
||||
else if(0 == aSerializedData)
|
||||
else if (!aSerializedData)
|
||||
{
|
||||
LOGE(" ## initWithSerializedDataJni(): failure - serialized data");
|
||||
}
|
||||
else if(NULL == (keyPtr = env->GetStringUTFChars(aKey, 0)))
|
||||
else if (!(keyPtr = env->GetStringUTFChars(aKey, 0)))
|
||||
{
|
||||
LOGE(" ## initWithSerializedDataJni(): failure - keyPtr JNI allocation OOM");
|
||||
}
|
||||
else if(NULL == (pickledPtr = env->GetStringUTFChars(aSerializedData, 0)))
|
||||
else if (!(pickledPtr = env->GetStringUTFChars(aSerializedData, 0)))
|
||||
{
|
||||
LOGE(" ## initWithSerializedDataJni(): failure - pickledPtr JNI allocation OOM");
|
||||
}
|
||||
|
@ -909,12 +914,12 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, j
|
|||
}
|
||||
|
||||
// free alloc
|
||||
if(NULL != keyPtr)
|
||||
if (keyPtr)
|
||||
{
|
||||
env->ReleaseStringUTFChars(aKey, keyPtr);
|
||||
}
|
||||
|
||||
if(NULL != pickledPtr)
|
||||
if (pickledPtr)
|
||||
{
|
||||
env->ReleaseStringUTFChars(aSerializedData, pickledPtr);
|
||||
}
|
||||
|
|
|
@ -21,10 +21,10 @@ using namespace AndroidOlmSdk;
|
|||
|
||||
OlmUtility* initializeUtilityMemory()
|
||||
{
|
||||
OlmUtility* utilityPtr = NULL;
|
||||
size_t utilitySize = olm_utility_size();
|
||||
OlmUtility* utilityPtr = (OlmUtility*)malloc(utilitySize);
|
||||
|
||||
if(NULL != (utilityPtr=(OlmUtility*)malloc(utilitySize)))
|
||||
if (utilityPtr)
|
||||
{
|
||||
utilityPtr = olm_utility(utilityPtr);
|
||||
LOGD("## initializeUtilityMemory(): success - OLM utility size=%lu",static_cast<long unsigned int>(utilitySize));
|
||||
|
@ -39,12 +39,12 @@ OlmUtility* initializeUtilityMemory()
|
|||
|
||||
JNIEXPORT jlong OLM_UTILITY_FUNC_DEF(initUtilityJni)(JNIEnv *env, jobject thiz)
|
||||
{
|
||||
OlmUtility* utilityPtr = NULL;
|
||||
OlmUtility* utilityPtr = initializeUtilityMemory();
|
||||
|
||||
LOGD("## initUtilityJni(): IN");
|
||||
|
||||
// init account memory allocation
|
||||
if(NULL == (utilityPtr = initializeUtilityMemory()))
|
||||
if (!utilityPtr)
|
||||
{
|
||||
LOGE(" ## initUtilityJni(): failure - init OOM");
|
||||
}
|
||||
|
@ -59,11 +59,11 @@ JNIEXPORT jlong OLM_UTILITY_FUNC_DEF(initUtilityJni)(JNIEnv *env, jobject thiz)
|
|||
|
||||
JNIEXPORT void OLM_UTILITY_FUNC_DEF(releaseUtilityJni)(JNIEnv *env, jobject thiz)
|
||||
{
|
||||
OlmUtility* utilityPtr = NULL;
|
||||
OlmUtility* utilityPtr = (OlmUtility*)getUtilityInstanceId(env,thiz);
|
||||
|
||||
LOGD("## releaseUtilityJni(): IN");
|
||||
|
||||
if(NULL == (utilityPtr = (OlmUtility*)getUtilityInstanceId(env,thiz)))
|
||||
if (!utilityPtr)
|
||||
{
|
||||
LOGE("## releaseUtilityJni(): failure - utility ptr=NULL");
|
||||
}
|
||||
|
@ -95,23 +95,23 @@ JNIEXPORT jstring OLM_UTILITY_FUNC_DEF(verifyEd25519SignatureJni)(JNIEnv *env, j
|
|||
|
||||
LOGD("## verifyEd25519SignatureJni(): IN");
|
||||
|
||||
if(NULL == (utilityPtr = (OlmUtility*)getUtilityInstanceId(env,thiz)))
|
||||
if (!(utilityPtr = (OlmUtility*)getUtilityInstanceId(env,thiz)))
|
||||
{
|
||||
LOGE(" ## verifyEd25519SignatureJni(): failure - invalid utility ptr=NULL");
|
||||
}
|
||||
else if((0 == aSignature) || (0 == aKey) || (0 == aMessage))
|
||||
else if (!aSignature || !aKey || !aMessage)
|
||||
{
|
||||
LOGE(" ## verifyEd25519SignatureJni(): failure - invalid input parameters ");
|
||||
}
|
||||
else if(0 == (signaturePtr = env->GetStringUTFChars(aSignature, 0)))
|
||||
else if (!(signaturePtr = env->GetStringUTFChars(aSignature, 0)))
|
||||
{
|
||||
LOGE(" ## verifyEd25519SignatureJni(): failure - signature JNI allocation OOM");
|
||||
}
|
||||
else if(0 == (keyPtr = env->GetStringUTFChars(aKey, 0)))
|
||||
else if (!(keyPtr = env->GetStringUTFChars(aKey, 0)))
|
||||
{
|
||||
LOGE(" ## verifyEd25519SignatureJni(): failure - key JNI allocation OOM");
|
||||
}
|
||||
else if(0 == (messagePtr = env->GetStringUTFChars(aMessage, 0)))
|
||||
else if (!(messagePtr = env->GetStringUTFChars(aMessage, 0)))
|
||||
{
|
||||
LOGE(" ## verifyEd25519SignatureJni(): failure - message JNI allocation OOM");
|
||||
}
|
||||
|
@ -142,17 +142,17 @@ JNIEXPORT jstring OLM_UTILITY_FUNC_DEF(verifyEd25519SignatureJni)(JNIEnv *env, j
|
|||
}
|
||||
|
||||
// free alloc
|
||||
if(NULL != signaturePtr)
|
||||
if (signaturePtr)
|
||||
{
|
||||
env->ReleaseStringUTFChars(aSignature, signaturePtr);
|
||||
}
|
||||
|
||||
if(NULL != keyPtr)
|
||||
if (keyPtr)
|
||||
{
|
||||
env->ReleaseStringUTFChars(aKey, keyPtr);
|
||||
}
|
||||
|
||||
if(NULL != messagePtr)
|
||||
if (messagePtr)
|
||||
{
|
||||
env->ReleaseStringUTFChars(aMessage, messagePtr);
|
||||
}
|
||||
|
@ -171,19 +171,18 @@ JNIEXPORT jstring OLM_UTILITY_FUNC_DEF(sha256Jni)(JNIEnv *env, jobject thiz, jst
|
|||
jstring sha256RetValue = 0;
|
||||
OlmUtility* utilityPtr = NULL;
|
||||
const char* messagePtr = NULL;
|
||||
void *hashValuePtr = NULL;
|
||||
|
||||
LOGD("## sha256Jni(): IN");
|
||||
|
||||
if(NULL == (utilityPtr = (OlmUtility*)getUtilityInstanceId(env,thiz)))
|
||||
if (!(utilityPtr = (OlmUtility*)getUtilityInstanceId(env,thiz)))
|
||||
{
|
||||
LOGE(" ## sha256Jni(): failure - invalid utility ptr=NULL");
|
||||
}
|
||||
else if(0 == aMessageToHash)
|
||||
else if(!aMessageToHash)
|
||||
{
|
||||
LOGE(" ## sha256Jni(): failure - invalid message parameters ");
|
||||
}
|
||||
else if(0 == (messagePtr = env->GetStringUTFChars(aMessageToHash, 0)))
|
||||
else if(!(messagePtr = env->GetStringUTFChars(aMessageToHash, 0)))
|
||||
{
|
||||
LOGE(" ## sha256Jni(): failure - message JNI allocation OOM");
|
||||
}
|
||||
|
@ -192,8 +191,9 @@ JNIEXPORT jstring OLM_UTILITY_FUNC_DEF(sha256Jni)(JNIEnv *env, jobject thiz, jst
|
|||
// get lengths
|
||||
size_t messageLength = (size_t)env->GetStringUTFLength(aMessageToHash);
|
||||
size_t hashLength = olm_sha256_length(utilityPtr);
|
||||
void* hashValuePtr = malloc((hashLength+1)*sizeof(uint8_t));
|
||||
|
||||
if(NULL == (hashValuePtr = static_cast<void*>(malloc((hashLength+1)*sizeof(uint8_t)))))
|
||||
if (!hashValuePtr)
|
||||
{
|
||||
LOGE("## sha256Jni(): failure - hash value allocation OOM");
|
||||
}
|
||||
|
@ -216,16 +216,12 @@ JNIEXPORT jstring OLM_UTILITY_FUNC_DEF(sha256Jni)(JNIEnv *env, jobject thiz, jst
|
|||
LOGD("## sha256Jni(): success - result=%lu hashValue=%s",static_cast<long unsigned int>(result), (char*)hashValuePtr);
|
||||
sha256RetValue = env->NewStringUTF((const char*)hashValuePtr);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(NULL != hashValuePtr)
|
||||
{
|
||||
free(hashValuePtr);
|
||||
}
|
||||
}
|
||||
|
||||
if(NULL != messagePtr)
|
||||
if (messagePtr)
|
||||
{
|
||||
env->ReleaseStringUTFChars(aMessageToHash, messagePtr);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue