aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorylecollen <ylecollen@amdocs.com>2017-01-04 08:57:41 +0100
committerylecollen <ylecollen@amdocs.com>2017-01-04 08:57:41 +0100
commitce9f67d5beb4cc46ded3f374afee6b737e505ff4 (patch)
tree07c0dc2708a9d644a25da20e1487b7b7665384d9
parent2070de4fc57980527dadd2ef88340e7455269e09 (diff)
Simplify the serialization / deserializtion methods (CommonSerializeUtils)
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java34
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/CommonSerializeUtils.java31
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java206
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java119
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java200
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmSession.java217
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp50
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.h4
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.cpp66
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.h6
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.cpp50
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.h4
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp51
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.h4
14 files changed, 500 insertions, 542 deletions
diff --git a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java
index 6c888d0..675d72c 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java
@@ -112,7 +112,7 @@ public class OlmSessionTest {
assertTrue(0!=aliceSession.getOlmSessionId());
// CREATE ALICE OUTBOUND SESSION and encrypt message to bob
- assertNotNull(aliceSession.initOutboundSessionWithAccount(aliceAccount, bobIdentityKey, bobOneTimeKey));
+ assertNotNull(aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, bobOneTimeKey));
String clearMsg = "Heloo bob , this is alice!";
OlmMessage encryptedMsgToBob = aliceSession.encryptMessage(clearMsg);
assertNotNull(encryptedMsgToBob);
@@ -129,7 +129,7 @@ public class OlmSessionTest {
assertTrue(0!=bobSession.getOlmSessionId());
try {
- bobSession.initInboundSessionWithAccount(bobAccount, encryptedMsgToBob.mCipherText);
+ bobSession.initInboundSession(bobAccount, encryptedMsgToBob.mCipherText);
} catch (Exception e) {
assertTrue("initInboundSessionWithAccount failed " + e.getMessage(), false);
}
@@ -211,7 +211,7 @@ public class OlmSessionTest {
assertTrue(0!=aliceSession.getOlmSessionId());
// CREATE ALICE OUTBOUND SESSION and encrypt message to bob
- assertNotNull(aliceSession.initOutboundSessionWithAccount(aliceAccount, bobIdentityKey, bobOneTimeKey));
+ assertNotNull(aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, bobOneTimeKey));
String helloClearMsg = "Hello I'm Alice!";
OlmMessage encryptedAliceToBobMsg1 = aliceSession.encryptMessage(helloClearMsg);
@@ -229,7 +229,7 @@ public class OlmSessionTest {
assertTrue(0!=bobSession.getOlmSessionId());
try {
- bobSession.initInboundSessionWithAccount(bobAccount, encryptedAliceToBobMsg1.mCipherText);
+ bobSession.initInboundSession(bobAccount, encryptedAliceToBobMsg1.mCipherText);
} catch (Exception e) {
assertTrue("initInboundSessionWithAccount failed " + e.getMessage(), false);
}
@@ -381,7 +381,7 @@ public class OlmSessionTest {
String bobOneTimeKey1 = TestHelper.getOneTimeKey(bobOneTimeKeys, 1);
// create alice inbound session for bob
- assertTrue(0==aliceSession.initOutboundSessionWithAccount(aliceAccount, bobIdentityKey, bobOneTimeKey1));
+ assertTrue(0==aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, bobOneTimeKey1));
String aliceClearMsg = "hello helooo to bob!";
OlmMessage encryptedAliceToBobMsg1 = aliceSession.encryptMessage(aliceClearMsg);
@@ -389,7 +389,7 @@ public class OlmSessionTest {
// init bob session with alice PRE KEY
try {
- bobSession.initInboundSessionWithAccount(bobAccount, encryptedAliceToBobMsg1.mCipherText);
+ bobSession.initInboundSession(bobAccount, encryptedAliceToBobMsg1.mCipherText);
} catch (Exception e) {
assertTrue("initInboundSessionWithAccount failed " + e.getMessage(), false);
}
@@ -463,7 +463,7 @@ public class OlmSessionTest {
assertTrue(0!=aliceSession.getOlmSessionId());
// CREATE ALICE OUTBOUND SESSION and encrypt message to bob
- assertNotNull(aliceSession.initOutboundSessionWithAccount(aliceAccount, bobIdentityKey, bobOneTimeKey));
+ assertNotNull(aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, bobOneTimeKey));
String helloClearMsg = "Hello I'm Alice!";
OlmMessage encryptedAliceToBobMsg1 = aliceSession.encryptMessage(helloClearMsg);
@@ -481,7 +481,7 @@ public class OlmSessionTest {
// init bob session with alice PRE KEY
try {
- bobSession.initInboundSessionWithAccount(bobAccount, encryptedAliceToBobMsg1.mCipherText);
+ bobSession.initInboundSession(bobAccount, encryptedAliceToBobMsg1.mCipherText);
} catch (Exception e) {
assertTrue("initInboundSessionWithAccount failed " + e.getMessage(), false);
}
@@ -608,13 +608,13 @@ public class OlmSessionTest {
}
// SANITY CHECK TESTS FOR: initOutboundSessionWithAccount()
- assertTrue(-1==aliceSession.initOutboundSessionWithAccount(null, bobIdentityKey, bobOneTimeKey));
- assertTrue(-1==aliceSession.initOutboundSessionWithAccount(aliceAccount, null, bobOneTimeKey));
- assertTrue(-1==aliceSession.initOutboundSessionWithAccount(aliceAccount, bobIdentityKey, null));
- assertTrue(-1==aliceSession.initOutboundSessionWithAccount(null, null, null));
+ assertTrue(-1==aliceSession.initOutboundSession(null, bobIdentityKey, bobOneTimeKey));
+ assertTrue(-1==aliceSession.initOutboundSession(aliceAccount, null, bobOneTimeKey));
+ assertTrue(-1==aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, null));
+ assertTrue(-1==aliceSession.initOutboundSession(null, null, null));
// init properly
- assertTrue(0==aliceSession.initOutboundSessionWithAccount(aliceAccount, bobIdentityKey, bobOneTimeKey));
+ assertTrue(0==aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, bobOneTimeKey));
// SANITY CHECK TESTS FOR: encryptMessage()
assertTrue(null==aliceSession.encryptMessage(null));
@@ -629,7 +629,7 @@ public class OlmSessionTest {
bobSession = new OlmSession();
String errorMessage = null;
try {
- bobSession.initInboundSessionWithAccount(null, encryptedMsgToBob.mCipherText);
+ bobSession.initInboundSession(null, encryptedMsgToBob.mCipherText);
} catch (Exception e) {
errorMessage = e.getMessage();
}
@@ -638,7 +638,7 @@ public class OlmSessionTest {
errorMessage = null;
try {
- bobSession.initInboundSessionWithAccount(bobAccount, null);
+ bobSession.initInboundSession(bobAccount, null);
} catch (Exception e) {
errorMessage = e.getMessage();
}
@@ -647,7 +647,7 @@ public class OlmSessionTest {
errorMessage = null;
try {
- bobSession.initInboundSessionWithAccount(bobAccount, INVALID_PRE_KEY);
+ bobSession.initInboundSession(bobAccount, INVALID_PRE_KEY);
} catch (Exception e) {
errorMessage = e.getMessage();
}
@@ -657,7 +657,7 @@ public class OlmSessionTest {
// init properly
errorMessage = null;
try {
- bobSession.initInboundSessionWithAccount(bobAccount, encryptedMsgToBob.mCipherText);
+ bobSession.initInboundSession(bobAccount, encryptedMsgToBob.mCipherText);
} catch (Exception e) {
errorMessage = e.getMessage();
}
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/CommonSerializeUtils.java b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/CommonSerializeUtils.java
index c3f9757..72437e4 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/CommonSerializeUtils.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/CommonSerializeUtils.java
@@ -35,7 +35,7 @@ abstract class CommonSerializeUtils {
* @param aOutStream output stream for serializing
* @throws IOException exception
*/
- protected void serializeObject(ObjectOutputStream aOutStream) throws IOException {
+ protected void serialize(ObjectOutputStream aOutStream) throws IOException {
aOutStream.defaultWriteObject();
// generate serialization key
@@ -43,7 +43,7 @@ abstract class CommonSerializeUtils {
// compute pickle string
StringBuffer errorMsg = new StringBuffer();
- String pickledData = serializeDataWithKey(key, errorMsg);
+ String pickledData = serialize(key, errorMsg);
if(null == pickledData) {
throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_SERIALIZATION, String.valueOf(errorMsg));
@@ -59,33 +59,22 @@ abstract class CommonSerializeUtils {
* @throws IOException exception
* @throws ClassNotFoundException exception
*/
- protected void deserializeObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
+ protected void deserialize(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
aInStream.defaultReadObject();
- StringBuffer errorMsg = new StringBuffer();
String key = (String) aInStream.readObject();
String pickledData = (String) aInStream.readObject();
- if(TextUtils.isEmpty(key)) {
+ if (TextUtils.isEmpty(key)) {
throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, OlmException.EXCEPTION_MSG_INVALID_PARAMS_DESERIALIZATION+" key");
-
- } else if(TextUtils.isEmpty(pickledData)) {
+ } else if (TextUtils.isEmpty(pickledData)) {
throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, OlmException.EXCEPTION_MSG_INVALID_PARAMS_DESERIALIZATION+" pickle");
-
- } else if(!createNewObjectFromSerialization()) {
- throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, OlmException.EXCEPTION_MSG_INIT_NEW_ACCOUNT_DESERIALIZATION);
-
- } else if(!initWithSerializedData(pickledData, key, errorMsg)) {
- releaseObjectFromSerialization(); // prevent memory leak
- throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, String.valueOf(errorMsg));
-
- } else {
- Log.d(LOG_TAG,"## readObject(): success");
}
+
+ deserialize(pickledData, key);
+ Log.d(LOG_TAG,"## deserializeObject(): success");
}
- protected abstract String serializeDataWithKey(String aKey, StringBuffer aErrorMsg);
- protected abstract boolean initWithSerializedData(String aSerializedData, String aKey, StringBuffer aErrorMsg);
- protected abstract boolean createNewObjectFromSerialization();
- protected abstract void releaseObjectFromSerialization();
+ protected abstract String serialize(String aKey, StringBuffer aErrorMsg);
+ protected abstract void deserialize(String aSerializedData, String aKey) throws IOException;
}
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java
index 1e41fa1..649085e 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java
@@ -69,105 +69,6 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
}
/**
- * Kick off the serialization mechanism.
- * @param aOutStream output stream for serializing
- * @throws IOException exception
- */
- private void writeObject(ObjectOutputStream aOutStream) throws IOException {
- serializeObject(aOutStream);
- }
-
- /**
- * Kick off the deserialization mechanism.
- * @param aInStream input stream
- * @throws IOException exception
- * @throws ClassNotFoundException exception
- */
- private void readObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
- deserializeObject(aInStream);
- }
-
- @Override
- protected boolean createNewObjectFromSerialization() {
- return createNewAccount();
- }
-
- @Override
- protected void releaseObjectFromSerialization() {
- releaseAccount();
- }
-
- /**
- * Return an account as a base64 string.<br>
- * The account is serialized and encrypted with aKey.
- * In case of failure, an error human readable
- * description is provide in aErrorMsg.
- * @param aKey encryption key
- * @param aErrorMsg error message description
- * @return pickled base64 string if operation succeed, null otherwise
- */
- @Override
- protected String serializeDataWithKey(String aKey, StringBuffer aErrorMsg) {
- String pickleRetValue = null;
-
- // sanity check
- if(null == aErrorMsg) {
- Log.e(LOG_TAG,"## serializeDataWithKey(): invalid parameter - aErrorMsg=null");
- } else if(TextUtils.isEmpty(aKey)) {
- aErrorMsg.append("Invalid input parameters in serializeDataWithKey()");
- } else {
- aErrorMsg.setLength(0);
- try {
- pickleRetValue = new String(serializeDataWithKeyJni(aKey.getBytes("UTF-8"), aErrorMsg), "UTF-8");
- } catch (Exception e) {
- Log.e(LOG_TAG, "## serializeDataWithKey() failed " + e.getMessage());
- aErrorMsg.append(e.getMessage());
- }
- }
-
- return pickleRetValue;
- }
- private native byte[] serializeDataWithKeyJni(byte[] aKey, StringBuffer aErrorMsg);
-
-
- /**
- * Loads an account from a pickled base64 string.<br>
- * See {@link #serializeDataWithKey(String, StringBuffer)}
- * @param aSerializedData pickled account in a base64 string format
- * @param aKey key used to encrypted
- * @param aErrorMsg error message description
- * @return true if operation succeed, false otherwise
- */
- @Override
- protected boolean initWithSerializedData(String aSerializedData, String aKey, StringBuffer aErrorMsg) {
- boolean retCode = false;
- String jniError;
-
- if (null == aErrorMsg) {
- Log.e(LOG_TAG, "## initWithSerializedData(): invalid input error parameter");
- } else {
- aErrorMsg.setLength(0);
-
- try {
- if (TextUtils.isEmpty(aSerializedData) || TextUtils.isEmpty(aKey)) {
- Log.e(LOG_TAG, "## initWithSerializedData(): invalid input parameters");
- } else if (null == (jniError = initWithSerializedDataJni(aSerializedData.getBytes("UTF-8"), aKey.getBytes("UTF-8")))) {
- retCode = true;
- } else {
- aErrorMsg.append(jniError);
- }
- } catch (Exception e) {
- Log.e(LOG_TAG, "## initWithSerializedData() failed " + e.getMessage());
- aErrorMsg.append(e.getMessage());
- }
- }
-
- return retCode;
- }
-
- private native String initWithSerializedDataJni(byte[] aSerializedDataBuffer, byte[] aKeyBuffer);
-
- /**
* Getter on the account ID.
* @return native account ID
*/
@@ -230,6 +131,14 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
private native long createNewAccountJni();
/**
+ * Return true the object resources have been released.<br>
+ * @return true the object resources have been released
+ */
+ public boolean isReleased() {
+ return (0 == mNativeId);
+ }
+
+ /**
* Return the identity keys (identity and fingerprint keys) in a dictionary.<br>
* Public API for {@link #identityKeysJni()}.<br>
* Ex:<tt>
@@ -394,14 +303,6 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
private native byte[] signMessageJni(byte[] aMessage);
/**
- * Return true the object resources have been released.<br>
- * @return true the object resources have been released
- */
- public boolean isReleased() {
- return (0 == mNativeId);
- }
-
- /**
* Build a string-string dictionary from a jsonObject.<br>
* @param jsonObject the object to parse
* @return the map
@@ -461,4 +362,95 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
return null;
}
+
+ //==============================================================================================================
+ // Serialization management
+ //==============================================================================================================
+
+ /**
+ * Kick off the serialization mechanism.
+ * @param aOutStream output stream for serializing
+ * @throws IOException exception
+ */
+ private void writeObject(ObjectOutputStream aOutStream) throws IOException {
+ serialize(aOutStream);
+ }
+
+ /**
+ * Kick off the deserialization mechanism.
+ * @param aInStream input stream
+ * @throws IOException exception
+ * @throws ClassNotFoundException exception
+ */
+ private void readObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
+ deserialize(aInStream);
+ }
+
+ /**
+ * Return an account as a base64 string.<br>
+ * The account is serialized and encrypted with aKey.
+ * In case of failure, an error human readable
+ * description is provide in aErrorMsg.
+ * @param aKey encryption key
+ * @param aErrorMsg error message description
+ * @return pickled base64 string if operation succeed, null otherwise
+ */
+ @Override
+ protected String serialize(String aKey, StringBuffer aErrorMsg) {
+ String pickleRetValue = null;
+
+ // sanity check
+ if(null == aErrorMsg) {
+ Log.e(LOG_TAG,"## serialize(): invalid parameter - aErrorMsg=null");
+ } else if(TextUtils.isEmpty(aKey)) {
+ aErrorMsg.append("Invalid input parameters in serializeDataWithKey()");
+ } else {
+ aErrorMsg.setLength(0);
+ try {
+ pickleRetValue = new String(serializeJni(aKey.getBytes("UTF-8"), aErrorMsg), "UTF-8");
+ } catch (Exception e) {
+ Log.e(LOG_TAG, "## serialize() failed " + e.getMessage());
+ aErrorMsg.append(e.getMessage());
+ }
+ }
+
+ return pickleRetValue;
+ }
+
+ private native byte[] serializeJni(byte[] aKey, StringBuffer aErrorMsg);
+
+ /**
+ * Loads an account from a pickled base64 string.<br>
+ * See {@link #serialize(String, StringBuffer)}
+ * @param aSerializedData pickled account in a base64 string format
+ * @param aKey key used to encrypted
+ */
+ @Override
+ protected void deserialize(String aSerializedData, String aKey) throws IOException {
+ if (!createNewAccount()) {
+ throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION);
+ }
+
+ StringBuffer errorMsg = new StringBuffer();
+
+ try {
+ String jniError;
+ if (TextUtils.isEmpty(aSerializedData) || TextUtils.isEmpty(aKey)) {
+ Log.e(LOG_TAG, "## deserialize(): invalid input parameters");
+ errorMsg.append("invalid input parameters");
+ } else if (null != (jniError = deserializeJni(aSerializedData.getBytes("UTF-8"), aKey.getBytes("UTF-8")))) {
+ errorMsg.append(jniError);
+ }
+ } catch (Exception e) {
+ Log.e(LOG_TAG, "## deserialize() failed " + e.getMessage());
+ errorMsg.append(e.getMessage());
+ }
+
+ if (errorMsg.length() > 0) {
+ releaseAccount();
+ throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, String.valueOf(errorMsg));
+ }
+ }
+
+ private native String deserializeJni(byte[] aSerializedDataBuffer, byte[] aKeyBuffer);
}
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java
index bfd50fb..68878c7 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java
@@ -65,13 +65,13 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
* Constructor.<br>
* Create and save a new native session instance ID and start a new inbound group session.
* The session key parameter is retrieved from an outbound group session
- * See {@link #createNewSession()} and {@link #initInboundGroupSessionWithSessionKey(String)}
+ * See {@link #createNewSession()} and {@link #initInboundGroupSession(String)}
* @param aSessionKey session key
* @throws OlmException constructor failure
*/
public OlmInboundGroupSession(String aSessionKey) throws OlmException {
if(createNewSession()) {
- if (0 != initInboundGroupSessionWithSessionKey(aSessionKey)) {
+ if (0 != initInboundGroupSession(aSessionKey)) {
releaseSession();// prevent memory leak before throwing
throw new OlmException(OlmException.EXCEPTION_CODE_INIT_INBOUND_GROUP_SESSION,OlmException.EXCEPTION_MSG_INIT_INBOUND_GROUP_SESSION);
}
@@ -115,29 +115,37 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
private native long createNewSessionJni();
/**
+ * Return true the object resources have been released.<br>
+ * @return true the object resources have been released
+ */
+ public boolean isReleased() {
+ return (0 == mNativeId);
+ }
+
+ /**
* Start a new inbound group session.<br>
* The session key parameter is retrieved from an outbound group session
* see {@link OlmOutboundGroupSession#sessionKey()}
* @param aSessionKey session key
* @return 0 if operation succeed, -1 otherwise
*/
- private int initInboundGroupSessionWithSessionKey(String aSessionKey) {
+ private int initInboundGroupSession(String aSessionKey) {
int retCode = -1;
if(TextUtils.isEmpty(aSessionKey)){
- Log.e(LOG_TAG, "## initInboundGroupSessionWithSessionKey(): invalid session key");
+ Log.e(LOG_TAG, "## initInboundGroupSession(): invalid session key");
} else {
try {
- retCode = initInboundGroupSessionWithSessionKeyJni(aSessionKey.getBytes("UTF-8"));
+ retCode = initInboundGroupSessionJni(aSessionKey.getBytes("UTF-8"));
} catch (Exception e) {
- Log.e(LOG_TAG, "## initInboundGroupSessionWithSessionKey() failed " + e.getMessage());
+ Log.e(LOG_TAG, "## initInboundGroupSession() failed " + e.getMessage());
}
}
return retCode;
}
- private native int initInboundGroupSessionWithSessionKeyJni(byte[] aSessionKeyBuffer);
+ private native int initInboundGroupSessionJni(byte[] aSessionKeyBuffer);
/**
* Retrieve the base64-encoded identifier for this inbound group session.
@@ -187,13 +195,17 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
private native byte[] decryptMessageJni(byte[] aEncryptedMsg, DecryptMessageResult aDecryptMessageResult, StringBuffer aErrorMsg);
+ //==============================================================================================================
+ // Serialization management
+ //==============================================================================================================
+
/**
* Kick off the serialization mechanism.
* @param aOutStream output stream for serializing
* @throws IOException exception
*/
private void writeObject(ObjectOutputStream aOutStream) throws IOException {
- serializeObject(aOutStream);
+ serialize(aOutStream);
}
/**
@@ -203,17 +215,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
* @throws ClassNotFoundException exception
*/
private void readObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
- deserializeObject(aInStream);
- }
-
- @Override
- protected boolean createNewObjectFromSerialization() {
- return createNewSession();
- }
-
- @Override
- protected void releaseObjectFromSerialization() {
- releaseSession();
+ deserialize(aInStream);
}
/**
@@ -226,20 +228,20 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
* @return pickled base64 string if operation succeed, null otherwise
*/
@Override
- protected String serializeDataWithKey(String aKey, StringBuffer aErrorMsg) {
+ protected String serialize(String aKey, StringBuffer aErrorMsg) {
String pickleRetValue = null;
// sanity check
if(null == aErrorMsg) {
- Log.e(LOG_TAG,"## serializeDataWithKey(): invalid parameter - aErrorMsg=null");
+ Log.e(LOG_TAG,"## serialize(): invalid parameter - aErrorMsg=null");
} else if(TextUtils.isEmpty(aKey)) {
- aErrorMsg.append("Invalid input parameters in serializeDataWithKey()");
+ aErrorMsg.append("Invalid input parameters in serialize()");
} else {
aErrorMsg.setLength(0);
try {
- pickleRetValue = new String(serializeDataWithKeyJni(aKey.getBytes("UTF-8"), aErrorMsg), "UTF-8");
+ pickleRetValue = new String(serializeJni(aKey.getBytes("UTF-8"), aErrorMsg), "UTF-8");
} catch (Exception e) {
- Log.e(LOG_TAG, "## serializeDataWithKey() failed " + e.getMessage());
+ Log.e(LOG_TAG, "## serialize() failed " + e.getMessage());
aErrorMsg.append(e.getMessage());
}
}
@@ -247,60 +249,51 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
return pickleRetValue;
}
/**
- * JNI counter part of {@link #serializeDataWithKey(String, StringBuffer)}.
+ * JNI counter part of {@link #serialize(String, StringBuffer)}.
* @param aKey encryption key
* @param aErrorMsg error message description
* @return pickled base64 string if operation succeed, null otherwise
*/
- private native byte[] serializeDataWithKeyJni(byte[] aKey, StringBuffer aErrorMsg);
-
+ private native byte[] serializeJni(byte[] aKey, StringBuffer aErrorMsg);
/**
- * Load an inbound group session from a pickled base64 string.<br>
- * See {@link #serializeDataWithKey(String, StringBuffer)}
- * @param aSerializedData pickled inbound group session in a base64 string format
- * @param aKey encrypting key used in {@link #serializeDataWithKey(String, StringBuffer)}
- * @param aErrorMsg error message description
- * @return true if operation succeed, false otherwise
+ * Loads an account from a pickled base64 string.<br>
+ * See {@link #serialize(String, StringBuffer)}
+ * @param aSerializedData pickled account in a base64 string format
+ * @param aKey key used to encrypted
*/
@Override
- protected boolean initWithSerializedData(String aSerializedData, String aKey, StringBuffer aErrorMsg) {
- boolean retCode = false;
- String jniError;
+ protected void deserialize(String aSerializedData, String aKey) throws IOException {
+ if (!createNewSession()) {
+ throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION);
+ }
- if(null == aErrorMsg) {
- Log.e(LOG_TAG, "## initWithSerializedData(): invalid input error parameter");
- } else {
- aErrorMsg.setLength(0);
- try {
- if (TextUtils.isEmpty(aSerializedData) || TextUtils.isEmpty(aKey)) {
- Log.e(LOG_TAG, "## initWithSerializedData(): invalid input parameters");
- } else if (null == (jniError = initWithSerializedDataJni(aSerializedData.getBytes("UTF-8"), aKey.getBytes("UTF-8")))) {
- retCode = true;
- } else {
- aErrorMsg.append(jniError);
- }
- } catch (Exception e) {
- Log.e(LOG_TAG, "## initWithSerializedData() failed " + e.getMessage());
- aErrorMsg.append(e.getMessage());
+ StringBuffer errorMsg = new StringBuffer();
+
+ try {
+ String jniError;
+ if (TextUtils.isEmpty(aSerializedData) || TextUtils.isEmpty(aKey)) {
+ Log.e(LOG_TAG, "## deserialize(): invalid input parameters");
+ errorMsg.append("invalid input parameters");
+ } else if (null != (jniError = deserializeJni(aSerializedData.getBytes("UTF-8"), aKey.getBytes("UTF-8")))) {
+ errorMsg.append(jniError);
}
+ } catch (Exception e) {
+ Log.e(LOG_TAG, "## deserialize() failed " + e.getMessage());
+ errorMsg.append(e.getMessage());
}
- return retCode;
+ if (errorMsg.length() > 0) {
+ releaseSession();
+ throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, String.valueOf(errorMsg));
+ }
}
+
/**
- * JNI counter part of {@link #initWithSerializedData(String, String, StringBuffer)}.
+ * JNI counter part of {@link #deserialize(String, String)}.
* @param aSerializedData pickled session in a base64 string format
- * @param aKey key used to encrypted in {@link #serializeDataWithKey(String, StringBuffer)}
+ * @param aKey key used to encrypted in {@link #serialize(String, StringBuffer)}
* @return null if operation succeed, an error message if operation failed
*/
- private native String initWithSerializedDataJni(byte[] aSerializedData, byte[] aKey);
-
- /**
- * Return true the object resources have been released.<br>
- * @return true the object resources have been released
- */
- public boolean isReleased() {
- return (0 == mNativeId);
- }
+ private native String deserializeJni(byte[] aSerializedData, byte[] aKey);
}
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java
index b9c21ff..66a44d2 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java
@@ -70,105 +70,6 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
}
/**
- * Kick off the serialization mechanism.
- * @param aOutStream output stream for serializing
- * @throws IOException exception
- */
- private void writeObject(ObjectOutputStream aOutStream) throws IOException {
- serializeObject(aOutStream);
- }
-
- /**
- * Kick off the deserialization mechanism.
- * @param aInStream input stream
- * @throws IOException exception
- * @throws ClassNotFoundException exception
- */
- private void readObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
- deserializeObject(aInStream);
- }
-
- @Override
- protected boolean createNewObjectFromSerialization() {
- return createNewSession();
- }
-
- @Override
- protected void releaseObjectFromSerialization() {
- releaseSession();
- }
-
- /**
- * Return the current outbound group session as a base64 serialized string.<br>
- * The session is serialized and encrypted with aKey.
- * In case of failure, an error human readable
- * description is provide in aErrorMsg.
- * @param aKey encryption key
- * @param aErrorMsg error message description
- * @return pickled base64 string if operation succeed, null otherwise
- */
- @Override
- protected String serializeDataWithKey(String aKey, StringBuffer aErrorMsg) {
- String pickleRetValue = null;
-
- // sanity check
- if(null == aErrorMsg) {
- Log.e(LOG_TAG,"## serializeDataWithKey(): invalid parameter - aErrorMsg=null");
- } else if(TextUtils.isEmpty(aKey)) {
- aErrorMsg.append("Invalid input parameters in serializeDataWithKey()");
- } else {
- aErrorMsg.setLength(0);
- try {
- pickleRetValue = serializeDataWithKeyJni(aKey.getBytes("UTF-8"), aErrorMsg);
- } catch (Exception e) {
- Log.e(LOG_TAG,"## serializeDataWithKey(): failed " + e.getMessage());
- aErrorMsg.append(e.getMessage());
- }
- }
-
- return pickleRetValue;
- }
- private native String serializeDataWithKeyJni(byte[] aKey, StringBuffer aErrorMsg);
-
-
- /**
- * Load an outbound group session from a pickled base64 string.<br>
- * See {@link #serializeDataWithKey(String, StringBuffer)}
- * @param aSerializedData pickled outbound group session in a base64 string format
- * @param aKey encrypting key used in {@link #serializeDataWithKey(String, StringBuffer)}
- * @param aErrorMsg error message description
- * @return true if operation succeed, false otherwise
- */
- @Override
- protected boolean initWithSerializedData(String aSerializedData, String aKey, StringBuffer aErrorMsg) {
- boolean retCode = false;
- String jniError;
-
- if(null == aErrorMsg) {
- Log.e(LOG_TAG, "## initWithSerializedData(): invalid input error parameter");
- } else {
- aErrorMsg.setLength(0);
-
- try {
- if (TextUtils.isEmpty(aSerializedData) || TextUtils.isEmpty(aKey)) {
- Log.e(LOG_TAG, "## initWithSerializedData(): invalid input parameters");
- } else if (null == (jniError = initWithSerializedDataJni(aSerializedData.getBytes("UTF-8"), aKey.getBytes("UTF-8")))) {
- retCode = true;
- } else {
- aErrorMsg.append(jniError);
- }
- } catch (Exception e) {
- Log.e(LOG_TAG, "## initWithSerializedData(): failed " + e.getMessage());
- aErrorMsg.append(e.getMessage());
- }
- }
-
- return retCode;
- }
- private native String initWithSerializedDataJni(byte[] aSerializedData, byte[] aKey);
-
-
- /**
* Release native session and invalid its JAVA reference counter part.<br>
* Public API for {@link #releaseSessionJni()}.
*/
@@ -204,6 +105,14 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
private native long createNewSessionJni();
/**
+ * Return true the object resources have been released.<br>
+ * @return true the object resources have been released
+ */
+ public boolean isReleased() {
+ return (0 == mNativeId);
+ }
+
+ /**
* Start a new outbound group session.<br>
* @return 0 if operation succeed, -1 otherwise
*/
@@ -290,11 +199,96 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
}
private native byte[] encryptMessageJni(byte[] aClearMsgBuffer, StringBuffer aErrorMsg);
+
+ //==============================================================================================================
+ // Serialization management
+ //==============================================================================================================
+
/**
- * Return true the object resources have been released.<br>
- * @return true the object resources have been released
+ * Kick off the serialization mechanism.
+ * @param aOutStream output stream for serializing
+ * @throws IOException exception
*/
- public boolean isReleased() {
- return (0 == mNativeId);
+ private void writeObject(ObjectOutputStream aOutStream) throws IOException {
+ serialize(aOutStream);
}
+
+ /**
+ * Kick off the deserialization mechanism.
+ * @param aInStream input stream
+ * @throws IOException exception
+ * @throws ClassNotFoundException exception
+ */
+ private void readObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
+ deserialize(aInStream);
+ }
+
+ /**
+ * Return the current outbound group session as a base64 serialized string.<br>
+ * The session is serialized and encrypted with aKey.
+ * In case of failure, an error human readable
+ * description is provide in aErrorMsg.
+ * @param aKey encryption key
+ * @param aErrorMsg error message description
+ * @return pickled base64 string if operation succeed, null otherwise
+ */
+ @Override
+ protected String serialize(String aKey, StringBuffer aErrorMsg) {
+ String pickleRetValue = null;
+
+ // sanity check
+ if(null == aErrorMsg) {
+ Log.e(LOG_TAG,"## serialize(): invalid parameter - aErrorMsg=null");
+ } else if(TextUtils.isEmpty(aKey)) {
+ aErrorMsg.append("Invalid input parameters in serialize()");
+ } else {
+ aErrorMsg.setLength(0);
+ try {
+ pickleRetValue = serializeJni(aKey.getBytes("UTF-8"), aErrorMsg);
+ } catch (Exception e) {
+ Log.e(LOG_TAG,"## serialize(): failed " + e.getMessage());
+ aErrorMsg.append(e.getMessage());
+ }
+ }
+
+ return pickleRetValue;
+ }
+ private native String serializeJni(byte[] aKey, StringBuffer aErrorMsg);
+
+
+ /**
+ * Loads an account from a pickled base64 string.<br>
+ * See {@link #serialize(String, StringBuffer)}
+ * @param aSerializedData pickled account in a base64 string format
+ * @param aKey key used to encrypted
+ */
+ @Override
+ protected void deserialize(String aSerializedData, String aKey) throws IOException {
+ if (!createNewSession()) {
+ throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION);
+ }
+
+ StringBuffer errorMsg = new StringBuffer();
+
+ try {
+ String jniError;
+ if (TextUtils.isEmpty(aSerializedData) || TextUtils.isEmpty(aKey)) {
+ Log.e(LOG_TAG, "## deserialize(): invalid input parameters");
+ errorMsg.append("invalid input parameters");
+ } else if (null != (jniError = deserializeJni(aSerializedData.getBytes("UTF-8"), aKey.getBytes("UTF-8")))) {
+ errorMsg.append(jniError);
+ }
+ } catch (Exception e) {
+ Log.e(LOG_TAG, "## deserialize() failed " + e.getMessage());
+ errorMsg.append(e.getMessage());
+ }
+
+ if (errorMsg.length() > 0) {
+ releaseSession();
+ throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, String.valueOf(errorMsg));
+ }
+ }
+
+ private native String deserializeJni(byte[] aSerializedData, byte[] aKey);
+
}
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmSession.java b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmSession.java
index 85804a1..36a95a1 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmSession.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmSession.java
@@ -28,8 +28,8 @@ import java.io.Serializable;
/**
* Session class used to create Olm sessions in conjunction with {@link OlmAccount} class.<br>
* Olm session is used to encrypt data between devices, especially to create Olm group sessions (see {@link OlmOutboundGroupSession} and {@link OlmInboundGroupSession}).<br>
- * To establish an Olm session with Bob, Alice calls {@link #initOutboundSessionWithAccount(OlmAccount, String, String)} with Bob's identity and onetime keys. Then Alice generates an encrypted PRE_KEY message ({@link #encryptMessage(String)})
- * used by Bob to open the Olm session in his side with {@link #initOutboundSessionWithAccount(OlmAccount, String, String)}.
+ * To establish an Olm session with Bob, Alice calls {@link #initOutboundSession(OlmAccount, String, String)} with Bob's identity and onetime keys. Then Alice generates an encrypted PRE_KEY message ({@link #encryptMessage(String)})
+ * used by Bob to open the Olm session in his side with {@link #initOutboundSession(OlmAccount, String, String)}.
* From this step on, messages can be exchanged by using {@link #encryptMessage(String)} and {@link #decryptMessage(OlmMessage)}.
* <br><br>Detailed implementation guide is available at <a href="http://matrix.org/docs/guides/e2e_implementation.html">Implementing End-to-End Encryption in Matrix clients</a>.
*/
@@ -49,104 +49,6 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
}
/**
- * Kick off the serialization mechanism.
- * @param aOutStream output stream for serializing
- * @throws IOException exception
- */
- private void writeObject(ObjectOutputStream aOutStream) throws IOException {
- serializeObject(aOutStream);
- }
-
- /**
- * Kick off the deserialization mechanism.
- * @param aInStream input stream
- * @throws IOException exception
- * @throws ClassNotFoundException exception
- */
- private void readObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
- deserializeObject(aInStream);
- }
-
- @Override
- protected boolean createNewObjectFromSerialization() {
- return createNewSession();
- }
-
- @Override
- protected void releaseObjectFromSerialization() {
- releaseSession();
- }
-
- /**
- * Return a session as a base64 string.<br>
- * The account is serialized and encrypted with aKey.
- * In case of failure, an error human readable
- * description is provide in aErrorMsg.
- * @param aKey encryption key
- * @param aErrorMsg error message description
- * @return pickled base64 string if operation succeed, null otherwise
- */
- @Override
- protected String serializeDataWithKey(String aKey, StringBuffer aErrorMsg) {
- String pickleRetValue = null;
-
- // sanity check
- if(null == aErrorMsg) {
- Log.e(LOG_TAG,"## serializeDataWithKey(): invalid parameter - aErrorMsg=null");
- } else if(TextUtils.isEmpty(aKey)) {
- aErrorMsg.append("Invalid input parameters in serializeDataWithKey()");
- } else {
- aErrorMsg.setLength(0);
- try {
- pickleRetValue = serializeDataWithKeyJni(aKey.getBytes("UTF-8"), aErrorMsg);
- } catch (Exception e) {
- Log.e(LOG_TAG,"## serializeDataWithKey(): failed " + e.getMessage());
- aErrorMsg.append(e.getMessage());
- }
- }
-
- return pickleRetValue;
- }
- private native String serializeDataWithKeyJni(byte[] aKey, StringBuffer aErrorMsg);
-
-
- /**
- * Loads a session from a pickled base64 string.<br>
- * See {@link #serializeDataWithKey(String, StringBuffer)}
- * @param aSerializedData pickled account in a base64 string format
- * @param aKey key used to encrypted
- * @param aErrorMsg error message description
- * @return true if operation succeed, false otherwise
- */
- @Override
- protected boolean initWithSerializedData(String aSerializedData, String aKey, StringBuffer aErrorMsg) {
- boolean retCode = false;
- String jniError;
-
- if(null == aErrorMsg) {
- Log.e(LOG_TAG, "## initWithSerializedData(): invalid input error parameter");
- } else {
- aErrorMsg.setLength(0);
-
- try {
- if (TextUtils.isEmpty(aSerializedData) || TextUtils.isEmpty(aKey)) {
- Log.e(LOG_TAG, "## initWithSerializedData(): invalid input parameters");
- } else if (null == (jniError = initWithSerializedDataJni(aSerializedData.getBytes("UTF-8"), aKey.getBytes("UTF-8")))) {
- retCode = true;
- } else {
- aErrorMsg.append(jniError);
- }
- } catch (Exception e) {
- Log.e(LOG_TAG, "## initWithSerializedData(): failed " + e.getMessage());
- aErrorMsg.append(e.getMessage());
- }
- }
-
- return retCode;
- }
- private native String initWithSerializedDataJni(byte[] aSerializedData, byte[] aKey);
-
- /**
* Getter on the session ID.
* @return native session ID
*/
@@ -189,7 +91,6 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
*/
private native long initNewSessionJni();
-
/**
* Create a native account instance without any initialization.<br>
* Since the account is left uninitialized, this
@@ -210,6 +111,14 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
private native long createNewSessionJni();
/**
+ * Return true the object resources have been released.<br>
+ * @return true the object resources have been released
+ */
+ public boolean isReleased() {
+ return (0 == mNativeId);
+ }
+
+ /**
* Creates a new out-bound session for sending messages to a recipient
* identified by an identity key and a one time key.<br>
* @param aAccount the account to associate with this session
@@ -217,7 +126,7 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
* @param aTheirOneTimeKey the one time key of the recipient
* @return 0 if operation succeed, -1 otherwise
*/
- public int initOutboundSessionWithAccount(OlmAccount aAccount, String aTheirIdentityKey, String aTheirOneTimeKey) {
+ public int initOutboundSession(OlmAccount aAccount, String aTheirIdentityKey, String aTheirOneTimeKey) {
int retCode=-1;
if ((null == aAccount) || TextUtils.isEmpty(aTheirIdentityKey) || TextUtils.isEmpty(aTheirOneTimeKey)) {
@@ -226,7 +135,7 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
try {
retCode = initOutboundSessionJni(aAccount.getOlmAccountId(), aTheirIdentityKey.getBytes("UTF-8"), aTheirOneTimeKey.getBytes("UTF-8"));
} catch (Exception e) {
- Log.e(LOG_TAG, "## initOutboundSessionWithAccount(): " + e.getMessage());
+ Log.e(LOG_TAG, "## initOutboundSession(): " + e.getMessage());
}
}
@@ -243,9 +152,9 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
* @param aPreKeyMsg PRE KEY message
* @exception Exception the failure reason
*/
- public void initInboundSessionWithAccount(OlmAccount aAccount, String aPreKeyMsg) throws Exception {
+ public void initInboundSession(OlmAccount aAccount, String aPreKeyMsg) throws Exception {
if ((null == aAccount) || TextUtils.isEmpty(aPreKeyMsg)){
- Log.e(LOG_TAG, "## initInboundSessionWithAccount(): invalid input parameters");
+ Log.e(LOG_TAG, "## initInboundSession(): invalid input parameters");
throw new Exception("invalid input parameters");
} else {
StringBuffer errorMsg = new StringBuffer();
@@ -253,7 +162,7 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
try {
initInboundSessionJni(aAccount.getOlmAccountId(), aPreKeyMsg.getBytes("UTF-8"), errorMsg);
} catch (Exception e) {
- Log.e(LOG_TAG, "## initInboundSessionWithAccount(): " + e.getMessage());
+ Log.e(LOG_TAG, "## initInboundSession(): " + e.getMessage());
errorMsg.append(errorMsg);
}
@@ -276,16 +185,16 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
* @param aPreKeyMsg PRE KEY message
* @return 0 if operation succeed, -1 otherwise
*/
- public int initInboundSessionWithAccountFrom(OlmAccount aAccount, String aTheirIdentityKey, String aPreKeyMsg) {
+ public int initInboundSessionFrom(OlmAccount aAccount, String aTheirIdentityKey, String aPreKeyMsg) {
int retCode=-1;
if((null==aAccount) || TextUtils.isEmpty(aPreKeyMsg)){
- Log.e(LOG_TAG, "## initInboundSessionWithAccount(): invalid input parameters");
+ Log.e(LOG_TAG, "## initInboundSessionFrom(): invalid input parameters");
} else {
try {
retCode = initInboundSessionFromIdKeyJni(aAccount.getOlmAccountId(), aTheirIdentityKey.getBytes("UTF-8"), aPreKeyMsg.getBytes("UTF-8"));
} catch (Exception e) {
- Log.e(LOG_TAG, "## initInboundSessionWithAccountFrom(): " + e.getMessage());
+ Log.e(LOG_TAG, "## initInboundSessionFrom(): " + e.getMessage());
}
}
@@ -400,12 +309,94 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
private native byte[] decryptMessageJni(OlmMessage aEncryptedMsg);
+ //==============================================================================================================
+ // Serialization management
+ //==============================================================================================================
+
/**
- * Return true the object resources have been released.<br>
- * @return true the object resources have been released
+ * Kick off the serialization mechanism.
+ * @param aOutStream output stream for serializing
+ * @throws IOException exception
*/
- public boolean isReleased() {
- return (0 == mNativeId);
+ private void writeObject(ObjectOutputStream aOutStream) throws IOException {
+ serialize(aOutStream);
}
+
+ /**
+ * Kick off the deserialization mechanism.
+ * @param aInStream input stream
+ * @throws IOException exception
+ * @throws ClassNotFoundException exception
+ */
+ private void readObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
+ deserialize(aInStream);
+ }
+
+ /**
+ * Return a session as a base64 string.<br>
+ * The account is serialized and encrypted with aKey.
+ * In case of failure, an error human readable
+ * description is provide in aErrorMsg.
+ * @param aKey encryption key
+ * @param aErrorMsg error message description
+ * @return pickled base64 string if operation succeed, null otherwise
+ */
+ @Override
+ protected String serialize(String aKey, StringBuffer aErrorMsg) {
+ String pickleRetValue = null;
+
+ // sanity check
+ if(null == aErrorMsg) {
+ Log.e(LOG_TAG,"## serializeDataWithKey(): invalid parameter - aErrorMsg=null");
+ } else if(TextUtils.isEmpty(aKey)) {
+ aErrorMsg.append("Invalid input parameters in serializeDataWithKey()");
+ } else {
+ aErrorMsg.setLength(0);
+ try {
+ pickleRetValue = serializeJni(aKey.getBytes("UTF-8"), aErrorMsg);
+ } catch (Exception e) {
+ Log.e(LOG_TAG,"## serializeDataWithKey(): failed " + e.getMessage());
+ aErrorMsg.append(e.getMessage());
+ }
+ }
+
+ return pickleRetValue;
+ }
+ private native String serializeJni(byte[] aKey, StringBuffer aErrorMsg);
+
+ /**
+ * Loads an account from a pickled base64 string.<br>
+ * See {@link #serialize(String, StringBuffer)}
+ * @param aSerializedData pickled account in a base64 string format
+ * @param aKey key used to encrypted
+ */
+ @Override
+ protected void deserialize(String aSerializedData, String aKey) throws IOException {
+ if (!createNewSession()) {
+ throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION);
+ }
+
+ StringBuffer errorMsg = new StringBuffer();
+
+ try {
+ String jniError;
+ if (TextUtils.isEmpty(aSerializedData) || TextUtils.isEmpty(aKey)) {
+ Log.e(LOG_TAG, "## deserialize(): invalid input parameters");
+ errorMsg.append("invalid input parameters");
+ } else if (null != (jniError = deserializeJni(aSerializedData.getBytes("UTF-8"), aKey.getBytes("UTF-8")))) {
+ errorMsg.append(jniError);
+ }
+ } catch (Exception e) {
+ Log.e(LOG_TAG, "## deserialize() failed " + e.getMessage());
+ errorMsg.append(e.getMessage());
+ }
+
+ if (errorMsg.length() > 0) {
+ releaseSession();
+ throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, String.valueOf(errorMsg));
+ }
+ }
+
+ private native String deserializeJni(byte[] aSerializedData, byte[] aKey);
}
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp
index 06709e7..d57e55b 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp
@@ -476,7 +476,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject t
* @param[out] aErrorMsg error message set if operation failed
* @return a base64 string if operation succeed, null otherwise
**/
-JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
+JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
{
jbyteArray pickledDataRetValue = 0;
jclass errorMsgJClass = 0;
@@ -485,44 +485,44 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env,
jbyte* keyPtr = NULL;
OlmAccount* accountPtr = NULL;
- LOGD("## serializeDataWithKeyJni(): IN");
+ LOGD("## serializeJni(): IN");
if (!aKeyBuffer)
{
- LOGE(" ## serializeDataWithKeyJni(): failure - invalid key");
+ LOGE(" ## serializeJni(): failure - invalid key");
}
else if (!aErrorMsg)
{
- LOGE(" ## serializeDataWithKeyJni(): failure - invalid error object");
+ LOGE(" ## serializeJni(): failure - invalid error object");
}
else if (!(accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz)))
{
- LOGE(" ## serializeDataWithKeyJni(): failure - invalid account ptr");
+ LOGE(" ## serializeJni(): failure - invalid account ptr");
}
else if (!(errorMsgJClass = env->GetObjectClass(aErrorMsg)))
{
- LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error class");
+ LOGE(" ## serializeJni(): failure - unable to get error class");
}
else if (!(errorMsgMethodId = env->GetMethodID(errorMsgJClass, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;")))
{
- LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error method ID");
+ LOGE(" ## serializeJni(): failure - unable to get error method ID");
}
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, NULL)))
{
- LOGE(" ## serializeDataWithKeyJni(): failure - keyPtr JNI allocation OOM");
+ LOGE(" ## serializeJni(): failure - keyPtr JNI allocation OOM");
}
else
{
size_t pickledLength = olm_pickle_account_length(accountPtr);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
- 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);
+ LOGD(" ## serializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
+ LOGD(" ## serializeJni(): key=%s",(char const *)keyPtr);
void *pickledPtr = malloc((pickledLength+1)*sizeof(uint8_t));
if (!pickledPtr)
{
- LOGE(" ## serializeDataWithKeyJni(): failure - pickledPtr buffer OOM");
+ LOGE(" ## serializeJni(): failure - pickledPtr buffer OOM");
}
else
{
@@ -534,7 +534,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env,
if (result == olm_error())
{
const char *errorMsgPtr = olm_account_last_error(accountPtr);
- LOGE(" ## serializeDataWithKeyJni(): failure - olm_pickle_account() Msg=%s",errorMsgPtr);
+ LOGE(" ## serializeJni(): failure - olm_pickle_account() Msg=%s",errorMsgPtr);
if(0 != (errorJstring = env->NewStringUTF(errorMsgPtr)))
{
@@ -546,7 +546,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env,
// build success output
(static_cast<char*>(pickledPtr))[pickledLength] = static_cast<char>('\0');
- LOGD(" ## serializeDataWithKeyJni(): success - result=%lu pickled=%s", static_cast<long unsigned int>(result), static_cast<char*>(pickledPtr));
+ LOGD(" ## serializeJni(): success - result=%lu pickled=%s", static_cast<long unsigned int>(result), static_cast<char*>(pickledPtr));
pickledDataRetValue = env->NewByteArray(pickledLength+1);
env->SetByteArrayRegion(pickledDataRetValue, 0 , pickledLength+1, (jbyte*)pickledPtr);
@@ -566,42 +566,42 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env,
}
-JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer)
+JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer)
{
OlmAccount* accountPtr = NULL;
jstring errorMessageRetValue = 0;
jbyte* keyPtr = NULL;
jbyte* pickledPtr = NULL;
- LOGD("## initWithSerializedDataJni(): IN");
+ LOGD("## deserializeJni(): IN");
if (!aKeyBuffer)
{
- LOGE(" ## initWithSerializedDataJni(): failure - invalid key");
+ LOGE(" ## deserializeJni(): failure - invalid key");
}
else if (!aSerializedDataBuffer)
{
- LOGE(" ## initWithSerializedDataJni(): failure - serialized data");
+ LOGE(" ## deserializeJni(): failure - serialized data");
}
else if (!(accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz)))
{
- LOGE(" ## initWithSerializedDataJni(): failure - account failure OOM");
+ LOGE(" ## deserializeJni(): failure - account failure OOM");
}
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
{
- LOGE(" ## initWithSerializedDataJni(): failure - keyPtr JNI allocation OOM");
+ LOGE(" ## deserializeJni(): failure - keyPtr JNI allocation OOM");
}
else if (!(pickledPtr = env->GetByteArrayElements(aSerializedDataBuffer, 0)))
{
- LOGE(" ## initWithSerializedDataJni(): failure - pickledPtr JNI allocation OOM");
+ LOGE(" ## deserializeJni(): failure - pickledPtr JNI allocation OOM");
}
else
{
size_t pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
- LOGD(" ## initWithSerializedDataJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
- LOGD(" ## initWithSerializedDataJni(): key=%s",(char const *)keyPtr);
- LOGD(" ## initWithSerializedDataJni(): pickled=%s",(char const *)pickledPtr);
+ LOGD(" ## deserializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
+ LOGD(" ## deserializeJni(): key=%s",(char const *)keyPtr);
+ LOGD(" ## deserializeJni(): pickled=%s",(char const *)pickledPtr);
size_t result = olm_unpickle_account(accountPtr,
(void const *)keyPtr,
@@ -611,12 +611,12 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, j
if (result == olm_error())
{
const char *errorMsgPtr = olm_account_last_error(accountPtr);
- LOGE(" ## initWithSerializedDataJni(): failure - olm_unpickle_account() Msg=%s",errorMsgPtr);
+ LOGE(" ## deserializeJni(): failure - olm_unpickle_account() Msg=%s",errorMsgPtr);
errorMessageRetValue = env->NewStringUTF(errorMsgPtr);
}
else
{
- LOGD(" ## initWithSerializedDataJni(): success - result=%lu ", static_cast<long unsigned int>(result));
+ LOGD(" ## deserializeJni(): success - result=%lu ", static_cast<long unsigned int>(result));
}
}
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.h b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.h
index c866dbc..94a0381 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.h
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.h
@@ -47,8 +47,8 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(markOneTimeKeysAsPublishedJni)(JNIEnv *env,
JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aMessage);
// serialization
-JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg);
-JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer);
+JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg);
+JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer);
#ifdef __cplusplus
}
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.cpp
index ca47dbb..d396eb9 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.cpp
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.cpp
@@ -86,41 +86,41 @@ JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *
* @param aSessionKey session key from an outbound session
* @return ERROR_CODE_OK if operation succeed, ERROR_CODE_KO otherwise
*/
-JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSessionKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aSessionKeyBuffer)
+JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionJni)(JNIEnv *env, jobject thiz, jbyteArray aSessionKeyBuffer)
{
jint retCode = ERROR_CODE_KO;
OlmInboundGroupSession *sessionPtr = NULL;
jbyte* sessionKeyPtr = NULL;
size_t sessionResult;
- LOGD("## initInboundGroupSessionWithSessionKeyJni(): inbound group session IN");
+ LOGD("## initInboundGroupSessionJni(): inbound group session IN");
if (!(sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
{
- LOGE(" ## initInboundGroupSessionWithSessionKeyJni(): failure - invalid inbound group session instance");
+ LOGE(" ## initInboundGroupSessionJni(): failure - invalid inbound group session instance");
}
else if (!aSessionKeyBuffer)
{
- LOGE(" ## initInboundGroupSessionWithSessionKeyJni(): failure - invalid aSessionKey");
+ LOGE(" ## initInboundGroupSessionJni(): failure - invalid aSessionKey");
}
else if (!(sessionKeyPtr = env->GetByteArrayElements(aSessionKeyBuffer, 0)))
{
- LOGE(" ## initInboundSessionFromIdKeyJni(): failure - session key JNI allocation OOM");
+ LOGE(" ## initInboundGroupSessionJni(): failure - session key JNI allocation OOM");
}
else
{
size_t sessionKeyLength = (size_t)env->GetArrayLength(aSessionKeyBuffer);
- LOGD(" ## initInboundSessionFromIdKeyJni(): sessionKeyLength=%lu",static_cast<long unsigned int>(sessionKeyLength));
+ LOGD(" ## initInboundGroupSessionJni(): sessionKeyLength=%lu",static_cast<long unsigned int>(sessionKeyLength));
sessionResult = olm_init_inbound_group_session(sessionPtr, (const uint8_t*)sessionKeyPtr, sessionKeyLength);
if (sessionResult == olm_error()) {
const char *errorMsgPtr = olm_inbound_group_session_last_error(sessionPtr);
- LOGE(" ## initInboundSessionFromIdKeyJni(): failure - init inbound session creation Msg=%s",errorMsgPtr);
+ LOGE(" ## initInboundGroupSessionJni(): failure - init inbound session creation Msg=%s",errorMsgPtr);
}
else
{
retCode = ERROR_CODE_OK;
- LOGD(" ## initInboundSessionFromIdKeyJni(): success - result=%lu", static_cast<long unsigned int>(sessionResult));
+ LOGD(" ## initInboundGroupSessionJni(): success - result=%lu", static_cast<long unsigned int>(sessionResult));
}
}
@@ -337,7 +337,7 @@ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEn
* @param[out] aErrorMsg error message set if operation failed
* @return a base64 string if operation succeed, null otherwise
**/
-JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
+JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
{
jbyteArray pickledDataRet = 0;
@@ -346,44 +346,44 @@ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)
jbyte* keyPtr = NULL;
OlmInboundGroupSession* sessionPtr = NULL;
- LOGD("## inbound group session serializeDataWithKeyJni(): IN");
+ LOGD("## inbound group session serializeJni(): IN");
if (!(sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
{
- LOGE(" ## serializeDataWithKeyJni(): failure - invalid session ptr");
+ LOGE(" ## serializeJni(): failure - invalid session ptr");
}
else if (!aKeyBuffer)
{
- LOGE(" ## serializeDataWithKeyJni(): failure - invalid key");
+ LOGE(" ## serializeJni(): failure - invalid key");
}
else if (!aErrorMsg)
{
- LOGE(" ## serializeDataWithKeyJni(): failure - invalid error object");
+ LOGE(" ## serializeJni(): failure - invalid error object");
}
else if (!(errorMsgJClass = env->GetObjectClass(aErrorMsg)))
{
- LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error class");
+ LOGE(" ## serializeJni(): failure - unable to get error class");
}
else if (!(errorMsgMethodId = env->GetMethodID(errorMsgJClass, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;")))
{
- LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error method ID");
+ LOGE(" ## serializeJni(): failure - unable to get error method ID");
}
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
{
- LOGE(" ## serializeDataWithKeyJni(): failure - keyPtr JNI allocation OOM");
+ LOGE(" ## serializeJni(): failure - keyPtr JNI allocation OOM");
}
else
{
size_t pickledLength = olm_pickle_inbound_group_session_length(sessionPtr);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
- 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);
+ LOGD(" ## serializeJni(): pickledLength=%lu keyLength=%lu", static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
+ LOGD(" ## serializeJni(): key=%s",(char const *)keyPtr);
void *pickledPtr = malloc((pickledLength+1)*sizeof(uint8_t));
if (!pickledPtr)
{
- LOGE(" ## serializeDataWithKeyJni(): failure - pickledPtr buffer OOM");
+ LOGE(" ## serializeJni(): failure - pickledPtr buffer OOM");
}
else
{
@@ -395,7 +395,7 @@ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)
if (result == olm_error())
{
const char *errorMsgPtr = olm_inbound_group_session_last_error(sessionPtr);
- LOGE(" ## serializeDataWithKeyJni(): failure - olm_pickle_outbound_group_session() Msg=%s",errorMsgPtr);
+ LOGE(" ## serializeJni(): failure - olm_pickle_outbound_group_session() Msg=%s",errorMsgPtr);
jstring errorJstring = env->NewStringUTF(errorMsgPtr);
@@ -407,7 +407,7 @@ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)
else
{
(static_cast<char*>(pickledPtr))[pickledLength] = static_cast<char>('\0');
- LOGD(" ## serializeDataWithKeyJni(): success - result=%lu pickled=%s", static_cast<long unsigned int>(result), static_cast<char*>(pickledPtr));
+ LOGD(" ## serializeJni(): success - result=%lu pickled=%s", static_cast<long unsigned int>(result), static_cast<char*>(pickledPtr));
pickledDataRet = env->NewByteArray(pickledLength);
env->SetByteArrayRegion(pickledDataRet, 0 , pickledLength, (jbyte*)pickledPtr);
@@ -427,42 +427,42 @@ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)
}
-JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer)
+JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer)
{
OlmInboundGroupSession* sessionPtr = NULL;
jstring errorMessageRetValue = 0;
jbyte* keyPtr = NULL;
jbyte* pickledPtr = NULL;
- LOGD("## initWithSerializedDataJni(): IN");
+ LOGD("## deserializeJni(): IN");
if (!(sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
{
- LOGE(" ## initWithSerializedDataJni(): failure - session failure OOM");
+ LOGE(" ## deserializeJni(): failure - session failure OOM");
}
else if (!aKeyBuffer)
{
- LOGE(" ## initWithSerializedDataJni(): failure - invalid key");
+ LOGE(" ## deserializeJni(): failure - invalid key");
}
else if (!aSerializedDataBuffer)
{
- LOGE(" ## initWithSerializedDataJni(): failure - serialized data");
+ LOGE(" ## deserializeJni(): failure - serialized data");
}
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
{
- LOGE(" ## initWithSerializedDataJni(): failure - keyPtr JNI allocation OOM");
+ LOGE(" ## deserializeJni(): failure - keyPtr JNI allocation OOM");
}
else if (!(pickledPtr = env->GetByteArrayElements(aSerializedDataBuffer, 0)))
{
- LOGE(" ## initWithSerializedDataJni(): failure - pickledPtr JNI allocation OOM");
+ LOGE(" ## deserializeJni(): failure - pickledPtr JNI allocation OOM");
}
else
{
size_t pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
- LOGD(" ## initWithSerializedDataJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
- LOGD(" ## initWithSerializedDataJni(): key=%s",(char const *)keyPtr);
- LOGD(" ## initWithSerializedDataJni(): pickled=%s",(char const *)pickledPtr);
+ LOGD(" ## deserializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
+ LOGD(" ## deserializeJni(): key=%s",(char const *)keyPtr);
+ LOGD(" ## deserializeJni(): pickled=%s",(char const *)pickledPtr);
size_t result = olm_unpickle_inbound_group_session(sessionPtr,
(void const *)keyPtr,
@@ -472,12 +472,12 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initWithSerializedDataJni)(
if (result == olm_error())
{
const char *errorMsgPtr = olm_inbound_group_session_last_error(sessionPtr);
- LOGE(" ## initWithSerializedDataJni(): failure - olm_unpickle_inbound_group_session() Msg=%s",errorMsgPtr);
+ LOGE(" ## deserializeJni(): failure - olm_unpickle_inbound_group_session() Msg=%s",errorMsgPtr);
errorMessageRetValue = env->NewStringUTF(errorMsgPtr);
}
else
{
- LOGD(" ## initWithSerializedDataJni(): success - result=%lu ", static_cast<long unsigned int>(result));
+ LOGD(" ## deserializeJni(): success - result=%lu ", static_cast<long unsigned int>(result));
}
}
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.h b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.h
index 7ed6d8b..0ef55cf 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.h
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.h
@@ -32,13 +32,13 @@ extern "C" {
JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz);
JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *env, jobject thiz);
-JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSessionKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aSessionKeyBuffer);
+JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionJni)(JNIEnv *env, jobject thiz, jbyteArray aSessionKeyBuffer);
JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz);
JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aEncryptedMsg, jobject aDecryptIndex, jobject aErrorMsg);
// serialization
-JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKey, jobject aErrorMsg);
-JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedData, jbyteArray aKey);
+JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKey, jobject aErrorMsg);
+JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedData, jbyteArray aKey);
#ifdef __cplusplus
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.cpp
index aa0e5e7..4168742 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.cpp
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.cpp
@@ -372,7 +372,7 @@ JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIE
* @param[out] aErrorMsg error message set if operation failed
* @return a base64 string if operation succeed, null otherwise
**/
-JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
+JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
{
jstring pickledDataRetValue = 0;
jclass errorMsgJClass = 0;
@@ -381,44 +381,44 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(J
jbyte* keyPtr = NULL;
OlmOutboundGroupSession* sessionPtr = NULL;
- LOGD("## outbound group session serializeDataWithKeyJni(): IN");
+ LOGD("## outbound group session serializeJni(): IN");
if (!(sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
{
- LOGE(" ## serializeDataWithKeyJni(): failure - invalid session ptr");
+ LOGE(" ## serializeJni(): failure - invalid session ptr");
}
else if (!aKeyBuffer)
{
- LOGE(" ## serializeDataWithKeyJni(): failure - invalid key");
+ LOGE(" ## serializeJni(): failure - invalid key");
}
else if (!aErrorMsg)
{
- LOGE(" ## serializeDataWithKeyJni(): failure - invalid error object");
+ LOGE(" ## serializeJni(): failure - invalid error object");
}
else if (!(errorMsgJClass = env->GetObjectClass(aErrorMsg)))
{
- LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error class");
+ LOGE(" ## serializeJni(): failure - unable to get error class");
}
else if (!(errorMsgMethodId = env->GetMethodID(errorMsgJClass, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;")))
{
- LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error method ID");
+ LOGE(" ## serializeJni(): failure - unable to get error method ID");
}
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
{
- LOGE(" ## serializeDataWithKeyJni(): failure - keyPtr JNI allocation OOM");
+ LOGE(" ## serializeJni(): failure - keyPtr JNI allocation OOM");
}
else
{
size_t pickledLength = olm_pickle_outbound_group_session_length(sessionPtr);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
- 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);
+ LOGD(" ## serializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
+ LOGD(" ## serializeJni(): key=%s",(char const *)keyPtr);
void *pickledPtr = malloc((pickledLength+1)*sizeof(uint8_t));
if(!pickledPtr)
{
- LOGE(" ## serializeDataWithKeyJni(): failure - pickledPtr buffer OOM");
+ LOGE(" ## serializeJni(): failure - pickledPtr buffer OOM");
}
else
{
@@ -430,7 +430,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(J
if (result == olm_error())
{
const char *errorMsgPtr = olm_outbound_group_session_last_error(sessionPtr);
- LOGE(" ## serializeDataWithKeyJni(): failure - olm_pickle_outbound_group_session() Msg=%s",errorMsgPtr);
+ LOGE(" ## serializeJni(): failure - olm_pickle_outbound_group_session() Msg=%s",errorMsgPtr);
if (!(errorJstring = env->NewStringUTF(errorMsgPtr)))
{
@@ -442,7 +442,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(J
// build success output
(static_cast<char*>(pickledPtr))[pickledLength] = static_cast<char>('\0');
pickledDataRetValue = env->NewStringUTF((const char*)pickledPtr);
- LOGD(" ## serializeDataWithKeyJni(): success - result=%lu pickled=%s", static_cast<long unsigned int>(result), static_cast<char*>(pickledPtr));
+ LOGD(" ## serializeJni(): success - result=%lu pickled=%s", static_cast<long unsigned int>(result), static_cast<char*>(pickledPtr));
}
}
@@ -459,42 +459,42 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(J
}
-JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer)
+JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer)
{
OlmOutboundGroupSession* sessionPtr = NULL;
jstring errorMessageRetValue = 0;
jbyte* keyPtr = NULL;
jbyte* pickledPtr = NULL;
- LOGD("## initWithSerializedDataJni(): IN");
+ LOGD("## deserializeJni(): IN");
if (!(sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
{
- LOGE(" ## initWithSerializedDataJni(): failure - session failure OOM");
+ LOGE(" ## deserializeJni(): failure - session failure OOM");
}
else if (!aKeyBuffer)
{
- LOGE(" ## initWithSerializedDataJni(): failure - invalid key");
+ LOGE(" ## deserializeJni(): failure - invalid key");
}
else if (!aSerializedDataBuffer)
{
- LOGE(" ## initWithSerializedDataJni(): failure - serialized data");
+ LOGE(" ## deserializeJni(): failure - serialized data");
}
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
{
- LOGE(" ## initWithSerializedDataJni(): failure - keyPtr JNI allocation OOM");
+ LOGE(" ## deserializeJni(): failure - keyPtr JNI allocation OOM");
}
else if (!(pickledPtr = env->GetByteArrayElements(aSerializedDataBuffer, 0)))
{
- LOGE(" ## initWithSerializedDataJni(): failure - pickledPtr JNI allocation OOM");
+ LOGE(" ## deserializeJni(): failure - pickledPtr JNI allocation OOM");
}
else
{
size_t pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
- LOGD(" ## initWithSerializedDataJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
- LOGD(" ## initWithSerializedDataJni(): key=%s",(char const *)keyPtr);
- LOGD(" ## initWithSerializedDataJni(): pickled=%s",(char const *)pickledPtr);
+ LOGD(" ## deserializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
+ LOGD(" ## deserializeJni(): key=%s",(char const *)keyPtr);
+ LOGD(" ## deserializeJni(): pickled=%s",(char const *)pickledPtr);
size_t result = olm_unpickle_outbound_group_session(sessionPtr,
(void const *)keyPtr,
@@ -504,12 +504,12 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initWithSerializedDataJni)
if (result == olm_error())
{
const char *errorMsgPtr = olm_outbound_group_session_last_error(sessionPtr);
- LOGE(" ## initWithSerializedDataJni(): failure - olm_unpickle_outbound_group_session() Msg=%s",errorMsgPtr);
+ LOGE(" ## deserializeJni(): failure - olm_unpickle_outbound_group_session() Msg=%s",errorMsgPtr);
errorMessageRetValue = env->NewStringUTF(errorMsgPtr);
}
else
{
- LOGD(" ## initWithSerializedDataJni(): success - result=%lu ", static_cast<long unsigned int>(result));
+ LOGD(" ## deserializeJni(): success - result=%lu ", static_cast<long unsigned int>(result));
}
}
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.h b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.h
index 37f0ea6..f954bef 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.h
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.h
@@ -40,8 +40,8 @@ JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *
JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aClearMsgBuffer, jobject aErrorMsg);
// serialization
-JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKey, jobject aErrorMsg);
-JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedData, jbyteArray aKey);
+JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKey, jobject aErrorMsg);
+JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedData, jbyteArray aKey);
#ifdef __cplusplus
}
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 3731d14..4a1717a 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
@@ -780,7 +780,7 @@ JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(getSessionIdentifierJni)(JNIEnv *env,
* @param[out] aErrorMsg error message set if operation failed
* @return a base64 string if operation succeed, null otherwise
**/
-JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
+JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
{
jstring pickledDataRetValue = 0;
jclass errorMsgJClass = 0;
@@ -789,44 +789,44 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, job
jbyte* keyPtr = NULL;
OlmSession* sessionPtr = NULL;
- LOGD("## serializeDataWithKeyJni(): IN");
+ LOGD("## serializeJni(): IN");
if (!(sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
{
- LOGE(" ## serializeDataWithKeyJni(): failure - invalid session ptr");
+ LOGE(" ## serializeJni(): failure - invalid session ptr");
}
else if (!aKeyBuffer)
{
- LOGE(" ## serializeDataWithKeyJni(): failure - invalid key");
+ LOGE(" ## serializeJni(): failure - invalid key");
}
else if (!aErrorMsg)
{
- LOGE(" ## serializeDataWithKeyJni(): failure - invalid error object");
+ LOGE(" ## serializeJni(): failure - invalid error object");
}
else if (!(errorMsgJClass = env->GetObjectClass(aErrorMsg)))
{
- LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error class");
+ LOGE(" ## serializeJni(): failure - unable to get error class");
}
else if (!(errorMsgMethodId = env->GetMethodID(errorMsgJClass, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;")))
{
- LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error method ID");
+ LOGE(" ## serializeJni(): failure - unable to get error method ID");
}
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
{
- LOGE(" ## serializeDataWithKeyJni(): failure - keyPtr JNI allocation OOM");
+ LOGE(" ## serializeJni(): failure - keyPtr JNI allocation OOM");
}
else
{
size_t pickledLength = olm_pickle_session_length(sessionPtr);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
- 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);
+ LOGD(" ## serializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
+ LOGD(" ## serializeJni(): key=%s",(char const *)keyPtr);
void *pickledPtr = malloc((pickledLength+1)*sizeof(uint8_t));
if (!pickledPtr)
{
- LOGE(" ## serializeDataWithKeyJni(): failure - pickledPtr buffer OOM");
+ LOGE(" ## serializeJni(): failure - pickledPtr buffer OOM");
}
else
{
@@ -838,7 +838,7 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, job
if (result == olm_error())
{
const char *errorMsgPtr = olm_session_last_error(sessionPtr);
- LOGE(" ## serializeDataWithKeyJni(): failure - olm_pickle_session() Msg=%s",errorMsgPtr);
+ LOGE(" ## serializeJni(): failure - olm_pickle_session() Msg=%s",errorMsgPtr);
if ((errorJstring = env->NewStringUTF(errorMsgPtr)))
{
@@ -850,7 +850,7 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, job
// build success output
(static_cast<char*>(pickledPtr))[pickledLength] = static_cast<char>('\0');
pickledDataRetValue = env->NewStringUTF((const char*)pickledPtr);
- LOGD(" ## serializeDataWithKeyJni(): success - result=%lu pickled=%s", static_cast<long unsigned int>(result), static_cast<char*>(pickledPtr));
+ LOGD(" ## serializeJni(): success - result=%lu pickled=%s", static_cast<long unsigned int>(result), static_cast<char*>(pickledPtr));
}
free(pickledPtr);
@@ -867,42 +867,42 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, job
}
-JNIEXPORT jstring OLM_SESSION_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer)
+JNIEXPORT jstring OLM_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer)
{
OlmSession* sessionPtr = NULL;
jstring errorMessageRetValue = 0;
jbyte* keyPtr = NULL;
jbyte* pickledPtr = NULL;
- LOGD("## initWithSerializedDataJni(): IN");
+ LOGD("## deserializeJni(): IN");
if (!(sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
{
- LOGE(" ## initWithSerializedDataJni(): failure - session failure OOM");
+ LOGE(" ## deserializeJni(): failure - session failure OOM");
}
else if (!aKeyBuffer)
{
- LOGE(" ## initWithSerializedDataJni(): failure - invalid key");
+ LOGE(" ## deserializeJni(): failure - invalid key");
}
else if (!aSerializedDataBuffer)
{
- LOGE(" ## initWithSerializedDataJni(): failure - serialized data");
+ LOGE(" ## deserializeJni(): failure - serialized data");
}
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
{
- LOGE(" ## initWithSerializedDataJni(): failure - keyPtr JNI allocation OOM");
+ LOGE(" ## deserializeJni(): failure - keyPtr JNI allocation OOM");
}
else if (!(pickledPtr = env->GetByteArrayElements(aSerializedDataBuffer, 0)))
{
- LOGE(" ## initWithSerializedDataJni(): failure - pickledPtr JNI allocation OOM");
+ LOGE(" ## deserializeJni(): failure - pickledPtr JNI allocation OOM");
}
else
{
size_t pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
- LOGD(" ## initWithSerializedDataJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
- LOGD(" ## initWithSerializedDataJni(): key=%s",(char const *)keyPtr);
- LOGD(" ## initWithSerializedDataJni(): pickled=%s",(char const *)pickledPtr);
+ LOGD(" ## deserializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
+ LOGD(" ## deserializeJni(): key=%s",(char const *)keyPtr);
+ LOGD(" ## deserializeJni(): pickled=%s",(char const *)pickledPtr);
size_t result = olm_unpickle_session(sessionPtr,
(void const *)keyPtr,
@@ -912,14 +912,13 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, j
if (result == olm_error())
{
const char *errorMsgPtr = olm_session_last_error(sessionPtr);
- LOGE(" ## initWithSerializedDataJni(): failure - olm_unpickle_account() Msg=%s",errorMsgPtr);
+ LOGE(" ## deserializeJni(): failure - olm_unpickle_account() Msg=%s",errorMsgPtr);
errorMessageRetValue = env->NewStringUTF(errorMsgPtr);
}
else
{
- LOGD(" ## initWithSerializedDataJni(): success - result=%lu ", static_cast<long unsigned int>(result));
+ LOGD(" ## initJni(): success - result=%lu ", static_cast<long unsigned int>(result));
}
-
}
// free alloc
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.h b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.h
index 9ce12d4..95b421b 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.h
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.h
@@ -50,8 +50,8 @@ JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobjec
JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(getSessionIdentifierJni)(JNIEnv *env, jobject thiz);
// serialization
-JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKey, jobject aErrorMsg);
-JNIEXPORT jstring OLM_SESSION_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedData, jbyteArray aKey);
+JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKey, jobject aErrorMsg);
+JNIEXPORT jstring OLM_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedData, jbyteArray aKey);
#ifdef __cplusplus
}