aboutsummaryrefslogtreecommitdiff
path: root/android/olm-sdk/src/main
diff options
context:
space:
mode:
authorValere <valeref@matrix.org>2019-04-10 11:26:58 +0200
committerValere <valeref@matrix.org>2019-04-10 12:24:00 +0200
commiteb7347bb524b830c1458d64411cd56fc58ad5b91 (patch)
treeb167ff5e145c66bc3ebea2f9db9f04183cc1b2ea /android/olm-sdk/src/main
parent16a28f297c8d8f782131575c02854904b424eb82 (diff)
Return string instead of byte array for b64 encoded data
Diffstat (limited to 'android/olm-sdk/src/main')
-rw-r--r--android/olm-sdk/src/main/java/org/matrix/olm/OlmSAS.java15
-rw-r--r--android/olm-sdk/src/main/jni/olm_sas.cpp6
2 files changed, 12 insertions, 9 deletions
diff --git a/android/olm-sdk/src/main/java/org/matrix/olm/OlmSAS.java b/android/olm-sdk/src/main/java/org/matrix/olm/OlmSAS.java
index 70cfb8c..4bd1579 100644
--- a/android/olm-sdk/src/main/java/org/matrix/olm/OlmSAS.java
+++ b/android/olm-sdk/src/main/java/org/matrix/olm/OlmSAS.java
@@ -86,8 +86,7 @@ public class OlmSAS {
throw new OlmException(OlmException.EXCEPTION_CODE_SAS_MISSING_THEIR_PKEY, "call setTheirPublicKey first");
}
try {
- byte[] shortBuffer = generateShortCodeJni(info.getBytes("UTF-8"), byteNumber);
- return shortBuffer;
+ return generateShortCodeJni(info.getBytes("UTF-8"), byteNumber);
} catch (Exception e) {
Log.e(LOG_TAG, "## sessionIdentifier(): " + e.getMessage());
throw new OlmException(OlmException.EXCEPTION_CODE_SAS_GENERATE_SHORT_CODE, e.getMessage());
@@ -95,20 +94,24 @@ public class OlmSAS {
}
- public byte[] calculateMac(String message, String info) throws OlmException {
+ public String calculateMac(String message, String info) throws OlmException {
try {
- return calculateMacJni(message.getBytes("UTF-8"), info.getBytes("UTF-8"));
+ byte[] bytes = calculateMacJni(message.getBytes("UTF-8"), info.getBytes("UTF-8"));
+ if (bytes != null) return new String(bytes, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new OlmException(OlmException.EXCEPTION_CODE_SAS_ERROR, e.getMessage());
}
+ return null;
}
- public byte[] calculateMacLongKdf(String message, String info) throws OlmException {
+ public String calculateMacLongKdf(String message, String info) throws OlmException {
try {
- return calculateMacLongKdfJni(message.getBytes("UTF-8"), info.getBytes("UTF-8"));
+ byte[] bytes = calculateMacLongKdfJni(message.getBytes("UTF-8"), info.getBytes("UTF-8"));
+ if (bytes != null) return new String(bytes, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new OlmException(OlmException.EXCEPTION_CODE_SAS_ERROR, e.getMessage());
}
+ return null;
}
/**
diff --git a/android/olm-sdk/src/main/jni/olm_sas.cpp b/android/olm-sdk/src/main/jni/olm_sas.cpp
index 40b9183..400934f 100644
--- a/android/olm-sdk/src/main/jni/olm_sas.cpp
+++ b/android/olm-sdk/src/main/jni/olm_sas.cpp
@@ -148,7 +148,7 @@ JNIEXPORT void OLM_SAS_FUNC_DEF(setTheirPubKey)(JNIEnv *env, jobject thiz,jbyteA
}
else if (!(pubKeyPtr = env->GetByteArrayElements(pubKeyBuffer, &pubKeyWasCopied)))
{
- LOGE(" ## generateShortCodeJni(): failure - info JNI allocation OOM");
+ LOGE(" ## setTheirPubKey(): failure - info JNI allocation OOM");
errorMessage = "info JNI allocation OOM";
}
else
@@ -230,7 +230,7 @@ JNIEXPORT jbyteArray OLM_SAS_FUNC_DEF(generateShortCodeJni)(JNIEnv *env, jobject
JNIEXPORT jbyteArray OLM_SAS_FUNC_DEF(calculateMacJni)(JNIEnv *env, jobject thiz,jbyteArray messageBuffer,jbyteArray infoBuffer) {
- LOGD("## calculateMacJni(): IN");
+ LOGD("## calculateMacJni(): IN");
const char* errorMessage = NULL;
jbyteArray returnValue = 0;
OlmSAS* sasPtr = getOlmSasInstanceId(env, thiz);
@@ -310,7 +310,7 @@ JNIEXPORT jbyteArray OLM_SAS_FUNC_DEF(calculateMacJni)(JNIEnv *env, jobject thiz
}
JNIEXPORT jbyteArray OLM_SAS_FUNC_DEF(calculateMacLongKdfJni)(JNIEnv *env, jobject thiz,jbyteArray messageBuffer,jbyteArray infoBuffer) {
- LOGD("## calculateMacLongKdfJni(): IN");
+ LOGD("## calculateMacLongKdfJni(): IN");
const char* errorMessage = NULL;
jbyteArray returnValue = 0;
OlmSAS* sasPtr = getOlmSasInstanceId(env, thiz);