Use a 4 spaces tabulation

This commit is contained in:
ylecollen 2017-01-02 16:02:17 +01:00
parent 8f3d5bed72
commit 47a52dcf41

View file

@ -32,15 +32,15 @@ bool setRandomInBuffer(JNIEnv *env, uint8_t **aBuffer2Ptr, size_t aRandomSize)
bool retCode = false;
int bufferLen = aRandomSize*sizeof(uint8_t);
if(NULL == aBuffer2Ptr)
if (!aBuffer2Ptr)
{
LOGE("## setRandomInBuffer(): failure - aBuffer=NULL");
}
else if(0 == aRandomSize)
else if(!aRandomSize)
{
LOGE("## setRandomInBuffer(): failure - random size=0");
}
else if(NULL == (*aBuffer2Ptr = (uint8_t*)malloc(bufferLen)))
else if (!(*aBuffer2Ptr = (uint8_t*)malloc(bufferLen)))
{
LOGE("## setRandomInBuffer(): failure - alloc mem OOM");
}
@ -48,8 +48,6 @@ bool setRandomInBuffer(JNIEnv *env, uint8_t **aBuffer2Ptr, size_t aRandomSize)
{
LOGD("## setRandomInBuffer(): randomSize=%lu",static_cast<long unsigned int>(aRandomSize));
bool secureRandomSucceeds = false;
// use the secureRandom class
jclass cls = env->FindClass("java/security/SecureRandom");
@ -67,13 +65,12 @@ bool setRandomInBuffer(JNIEnv *env, uint8_t **aBuffer2Ptr, size_t aRandomSize)
if (newObj && tempByteArray)
{
env->CallVoidMethod(newObj, nextByteMethod, tempByteArray);
jbyte* buffer = env->GetByteArrayElements(tempByteArray, NULL);
if (buffer)
{
memcpy(*aBuffer2Ptr, buffer, bufferLen);
secureRandomSucceeds = true;
retCode = true;
// clear tempByteArray to hide sensitive data.
memset(buffer, 0, bufferLen);
@ -96,32 +93,16 @@ bool setRandomInBuffer(JNIEnv *env, uint8_t **aBuffer2Ptr, size_t aRandomSize)
}
}
if (!secureRandomSucceeds)
{
LOGE("## setRandomInBuffer(): SecureRandom failed, use a fallback");
struct timeval timeValue;
gettimeofday(&timeValue, NULL);
srand(timeValue.tv_usec); // init seed
for(size_t i=0;i<aRandomSize;i++)
{
(*aBuffer2Ptr)[i] = (uint8_t)(rand()%ACCOUNT_CREATION_RANDOM_MODULO);
}
}
// debug purpose
/*for(int i = 0; i < aRandomSize; i++)
{
LOGD("## setRandomInBuffer(): randomBuffPtr[%ld]=%d",i, (*aBuffer2Ptr)[i]);
}*/
retCode = true;
}
return retCode;
}
/**
* Read the instance ID of the calling object.
* @param aJniEnv pointer pointing on the JNI function table
@ -132,21 +113,20 @@ bool setRandomInBuffer(JNIEnv *env, uint8_t **aBuffer2Ptr, size_t aRandomSize)
jlong getInstanceId(JNIEnv* aJniEnv, jobject aJavaObject, const char *aCallingClass)
{
jlong instanceId = 0;
jfieldID instanceIdField = 0;
jclass loaderClass = 0;
jclass requiredClass = 0;
if(NULL!=aJniEnv)
if (aJniEnv)
{
requiredClass = aJniEnv->FindClass(aCallingClass);
jclass requiredClass = aJniEnv->FindClass(aCallingClass);
jclass loaderClass = 0;
if((0 != requiredClass) && (JNI_TRUE != aJniEnv->IsInstanceOf(aJavaObject, requiredClass)))
if (requiredClass && (JNI_TRUE != aJniEnv->IsInstanceOf(aJavaObject, requiredClass)))
{
LOGE("## getAccountInstanceId() failure - invalid instance of");
}
else if(0 != (loaderClass=aJniEnv->GetObjectClass(aJavaObject)))
else if (loaderClass = aJniEnv->GetObjectClass(aJavaObject))
{
if(0 != (instanceIdField=aJniEnv->GetFieldID(loaderClass, "mNativeId", "J")))
jfieldID instanceIdField = aJniEnv->GetFieldID(loaderClass, "mNativeId", "J");
if (instanceIdField)
{
instanceId = aJniEnv->GetLongField(aJavaObject, instanceIdField);
LOGD("## getInstanceId(): read from java instanceId=%lld",instanceId);
@ -155,6 +135,8 @@ jlong getInstanceId(JNIEnv* aJniEnv, jobject aJavaObject, const char *aCallingCl
{
LOGE("## getInstanceId() ERROR! GetFieldID=null");
}
aJniEnv->DeleteLocalRef(loaderClass);
}
else
{
@ -168,11 +150,6 @@ jlong getInstanceId(JNIEnv* aJniEnv, jobject aJavaObject, const char *aCallingCl
LOGD("## getInstanceId() success - instanceId=%p (jlong)(intptr_t)instanceId=%lld",(void*)instanceId, (jlong)(intptr_t)instanceId);
if (loaderClass)
{
aJniEnv->DeleteLocalRef(loaderClass);
}
return instanceId;
}
@ -188,8 +165,6 @@ jlong getAccountInstanceId(JNIEnv* aJniEnv, jobject aJavaObject)
return instanceId;
}
/**
* Read the session instance ID of the calling object (aJavaObject).<br>
* @param aJniEnv pointer pointing on the JNI function table
@ -214,7 +189,6 @@ jlong getInboundGroupSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject)
return instanceId;
}
/**
* Read the outbound group session instance ID of the calling object (aJavaObject).<br>
* @param aJniEnv pointer pointing on the JNI function table
@ -239,7 +213,6 @@ jlong getUtilityInstanceId(JNIEnv* aJniEnv, jobject aJavaObject)
return instanceId;
}
/**
* Convert a C string into a UTF-8 format string.
* The conversion is performed in JAVA side to workaround the issue in NewStringUTF().
@ -250,11 +223,11 @@ jstring javaCStringToUtf8(JNIEnv *env, uint8_t *aCStringMsgPtr, size_t aMsgLengt
jstring convertedRetValue = 0;
jbyteArray tempByteArray = NULL;
if((NULL == aCStringMsgPtr) || (NULL == env))
if (!aCStringMsgPtr || !env)
{
LOGE("## javaCStringToUtf8(): failure - invalid parameters (null)");
}
else if(NULL == (tempByteArray=env->NewByteArray(aMsgLength)))
else if (!(tempByteArray=env->NewByteArray(aMsgLength)))
{
LOGE("## javaCStringToUtf8(): failure - return byte array OOM");
}
@ -267,7 +240,7 @@ jstring javaCStringToUtf8(JNIEnv *env, uint8_t *aCStringMsgPtr, size_t aMsgLengt
jclass jClass = env->FindClass("java/lang/String");
jmethodID cstor = env->GetMethodID(jClass, "<init>", "([BLjava/lang/String;)V");
if((0!=jClass) && (0!=jClass) && (0!=strEncode))
if (jClass && strEncode)
{
convertedRetValue = (jstring) env->NewObject(jClass, cstor, tempByteArray, strEncode);
LOGD(" ## javaCStringToUtf8(): succeed");