aboutsummaryrefslogtreecommitdiff
path: root/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.cpp
diff options
context:
space:
mode:
authorpedroGitt <pedro.contreiras@amdocs.com>2016-10-06 19:55:03 +0200
committerpedroGitt <pedro.contreiras@amdocs.com>2016-10-06 19:55:03 +0200
commit655c841cc3720d1bb9892d60a2d7ca136c90cfbd (patch)
treee598da0ee20e90620873e7c13d36c9b32a3fe8d4 /java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.cpp
parent0393ad68438669f60a6679c9e0f8010c7366c5ed (diff)
- Update Unit tests for OlmAccount
- new file olm_utility.cpp to have a stand alone function to initialize/alloc a random buffer - new class OlmMessage - complete OlmSession API with encryptMessage() - comments review - OlmAccount unit tests are green - new gradle to compile the shared lib according to debug mode
Diffstat (limited to 'java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.cpp')
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.cpp
new file mode 100644
index 0000000..9abd228
--- /dev/null
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.cpp
@@ -0,0 +1,60 @@
+/**
+ * Created by pedrocon on 06/10/2016.
+ */
+/*
+ * Copyright 2016 OpenMarket Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "olm_jni.h"
+#include "olm_utility.h"
+
+/**
+* Init a buffer with a given number of random values.
+* @param aBuffer2Ptr the buffer to be initialized
+* @param aRandomSize the number of random values to apply
+* @return true if operation succeed, false otherwise
+**/
+bool setRandomInBuffer(uint8_t **aBuffer2Ptr, size_t aRandomSize)
+{
+ bool retCode = false;
+ if(NULL == aBuffer2Ptr)
+ {
+ LOGD("## setRandomInBuffer(): failure - aBuffer=NULL");
+ }
+ else if(0 == aRandomSize)
+ {
+ LOGD("## setRandomInBuffer(): failure - random size=0");
+ }
+ else if(NULL == (*aBuffer2Ptr = (uint8_t*)malloc(aRandomSize*sizeof(uint8_t))))
+ {
+ LOGD("## setRandomInBuffer(): failure - alloc mem OOM");
+ }
+ else
+ {
+ LOGD("## setRandomInBuffer(): randomSize=%ld",aRandomSize);
+
+ srand(time(NULL)); // init seed
+ for(size_t i=0;i<aRandomSize;i++)
+ {
+ (*aBuffer2Ptr)[i] = (uint8_t)(rand()%ACCOUNT_CREATION_RANDOM_MODULO);
+
+ // TODO debug purpose - remove asap
+ LOGD("## setRandomInBuffer(): randomBuffPtr[%ld]=%d",i, (*aBuffer2Ptr)[i]);
+ }
+
+ retCode = true;
+ }
+ return retCode;
+} \ No newline at end of file