Commit 9df5dd9c authored by ylecollen's avatar ylecollen
Browse files

The olm objects are serialized as byte[] instead of strings.

parent 7f6a6306
...@@ -39,11 +39,11 @@ abstract class CommonSerializeUtils { ...@@ -39,11 +39,11 @@ abstract class CommonSerializeUtils {
aOutStream.defaultWriteObject(); aOutStream.defaultWriteObject();
// generate serialization key // generate serialization key
String key = OlmUtility.getRandomKey(); byte[] key = OlmUtility.getRandomKey();
// compute pickle string // compute pickle string
StringBuffer errorMsg = new StringBuffer(); StringBuffer errorMsg = new StringBuffer();
String pickledData = serialize(key, errorMsg); byte[] pickledData = serialize(key, errorMsg);
if(null == pickledData) { if(null == pickledData) {
throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_SERIALIZATION, String.valueOf(errorMsg)); throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_SERIALIZATION, String.valueOf(errorMsg));
...@@ -62,12 +62,12 @@ abstract class CommonSerializeUtils { ...@@ -62,12 +62,12 @@ abstract class CommonSerializeUtils {
protected void deserialize(ObjectInputStream aInStream) throws IOException, ClassNotFoundException { protected void deserialize(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
aInStream.defaultReadObject(); aInStream.defaultReadObject();
String key = (String) aInStream.readObject(); byte[] key = (byte[]) aInStream.readObject();
String pickledData = (String) aInStream.readObject(); byte[] pickledData = (byte[]) aInStream.readObject();
if (TextUtils.isEmpty(key)) { if (null == key) {
throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, OlmException.EXCEPTION_MSG_INVALID_PARAMS_DESERIALIZATION+" key"); throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, OlmException.EXCEPTION_MSG_INVALID_PARAMS_DESERIALIZATION+" key");
} else if (TextUtils.isEmpty(pickledData)) { } else if (null == pickledData) {
throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, OlmException.EXCEPTION_MSG_INVALID_PARAMS_DESERIALIZATION+" pickle"); throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, OlmException.EXCEPTION_MSG_INVALID_PARAMS_DESERIALIZATION+" pickle");
} }
...@@ -75,6 +75,6 @@ abstract class CommonSerializeUtils { ...@@ -75,6 +75,6 @@ abstract class CommonSerializeUtils {
Log.d(LOG_TAG,"## deserializeObject(): success"); Log.d(LOG_TAG,"## deserializeObject(): success");
} }
protected abstract String serialize(String aKey, StringBuffer aErrorMsg); protected abstract byte[] serialize(byte[] aKey, StringBuffer aErrorMsg);
protected abstract void deserialize(String aSerializedData, String aKey) throws IOException; protected abstract void deserialize(byte[] aSerializedData, byte[] aKey) throws IOException;
} }
...@@ -418,27 +418,27 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable { ...@@ -418,27 +418,27 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
} }
/** /**
* Return an account as a base64 string.<br> * Return an account as a bytes buffer.<br>
* The account is serialized and encrypted with aKey. * The account is serialized and encrypted with aKey.
* In case of failure, an error human readable * In case of failure, an error human readable
* description is provide in aErrorMsg. * description is provide in aErrorMsg.
* @param aKey encryption key * @param aKey encryption key
* @param aErrorMsg error message description * @param aErrorMsg error message description
* @return pickled base64 string if operation succeed, null otherwise * @return the account as bytes buffer
*/ */
@Override @Override
protected String serialize(String aKey, StringBuffer aErrorMsg) { protected byte[] serialize(byte[] aKey, StringBuffer aErrorMsg) {
String pickleRetValue = null; byte[] pickleRetValue = null;
// sanity check // sanity check
if(null == aErrorMsg) { if(null == aErrorMsg) {
Log.e(LOG_TAG,"## serialize(): invalid parameter - aErrorMsg=null"); Log.e(LOG_TAG,"## serialize(): invalid parameter - aErrorMsg=null");
} else if(TextUtils.isEmpty(aKey)) { } else if (null == aKey) {
aErrorMsg.append("Invalid input parameters in serializeDataWithKey()"); aErrorMsg.append("Invalid input parameters in serializeDataWithKey()");
} else { } else {
aErrorMsg.setLength(0); aErrorMsg.setLength(0);
try { try {
pickleRetValue = new String(serializeJni(aKey.getBytes("UTF-8")), "UTF-8"); pickleRetValue = serializeJni(aKey);
} catch (Exception e) { } catch (Exception e) {
Log.e(LOG_TAG, "## serialize() failed " + e.getMessage()); Log.e(LOG_TAG, "## serialize() failed " + e.getMessage());
aErrorMsg.append(e.getMessage()); aErrorMsg.append(e.getMessage());
...@@ -451,13 +451,13 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable { ...@@ -451,13 +451,13 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
private native byte[] serializeJni(byte[] aKey); private native byte[] serializeJni(byte[] aKey);
/** /**
* Loads an account from a pickled base64 string.<br> * Loads an account from a pickled bytes buffer.<br>
* See {@link #serialize(String, StringBuffer)} * See {@link #serialize(byte[], StringBuffer)}
* @param aSerializedData pickled account in a base64 string format * @param aSerializedData bytes buffer
* @param aKey key used to encrypted * @param aKey key used to encrypted
*/ */
@Override @Override
protected void deserialize(String aSerializedData, String aKey) throws IOException { protected void deserialize(byte[] aSerializedData, byte[] aKey) throws IOException {
if (!createNewAccount()) { if (!createNewAccount()) {
throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION); throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION);
} }
...@@ -466,10 +466,10 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable { ...@@ -466,10 +466,10 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
try { try {
String jniError; String jniError;
if (TextUtils.isEmpty(aSerializedData) || TextUtils.isEmpty(aKey)) { if ((null == aSerializedData) || (null == aKey)) {
Log.e(LOG_TAG, "## deserialize(): invalid input parameters"); Log.e(LOG_TAG, "## deserialize(): invalid input parameters");
errorMsg.append("invalid input parameters"); errorMsg.append("invalid input parameters");
} else if (null != (jniError = deserializeJni(aSerializedData.getBytes("UTF-8"), aKey.getBytes("UTF-8")))) { } else if (null != (jniError = deserializeJni(aSerializedData, aKey))) {
errorMsg.append(jniError); errorMsg.append(jniError);
} }
} catch (Exception e) { } catch (Exception e) {
......
...@@ -44,7 +44,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri ...@@ -44,7 +44,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
/** /**
* Result in {@link #decryptMessage(String)} * Result in {@link #decryptMessage(String)}
*/ */
static class DecryptMessageResult { public static class DecryptMessageResult {
/** decrypt message **/ /** decrypt message **/
public String mDecryptedMessage; public String mDecryptedMessage;
...@@ -135,6 +135,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri ...@@ -135,6 +135,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
/** /**
* Retrieve the base64-encoded identifier for this inbound group session. * Retrieve the base64-encoded identifier for this inbound group session.
* @return the session ID * @return the session ID
* @throws OlmException the failure reason
*/ */
public String sessionIdentifier() throws OlmException { public String sessionIdentifier() throws OlmException {
try { try {
...@@ -197,28 +198,28 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri ...@@ -197,28 +198,28 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
} }
/** /**
* Return the current inbound group session as a base64 serialized string.<br> * Return the current inbound group session as a bytes buffer.<br>
* The session is serialized and encrypted with aKey. * The session is serialized and encrypted with aKey.
* In case of failure, an error human readable * In case of failure, an error human readable
* description is provide in aErrorMsg. * description is provide in aErrorMsg.
* @param aKey encryption key * @param aKey encryption key
* @param aErrorMsg error message description * @param aErrorMsg error message description
* @return pickled base64 string if operation succeed, null otherwise * @return pickled bytes buffer if operation succeed, null otherwise
*/ */
@Override @Override
protected String serialize(String aKey, StringBuffer aErrorMsg) { protected byte[] serialize(byte[] aKey, StringBuffer aErrorMsg) {
String pickleRetValue = null; byte[] pickleRetValue = null;
// sanity check // sanity check
if(null == aErrorMsg) { if(null == aErrorMsg) {
Log.e(LOG_TAG,"## serialize(): invalid parameter - aErrorMsg=null"); Log.e(LOG_TAG,"## serialize(): invalid parameter - aErrorMsg=null");
aErrorMsg.append("aErrorMsg=null"); aErrorMsg.append("aErrorMsg=null");
} else if(TextUtils.isEmpty(aKey)) { } else if (null == aKey) {
aErrorMsg.append("Invalid input parameters in serialize()"); aErrorMsg.append("Invalid input parameters in serialize()");
} else { } else {
aErrorMsg.setLength(0); aErrorMsg.setLength(0);
try { try {
pickleRetValue = new String(serializeJni(aKey.getBytes("UTF-8")), "UTF-8"); pickleRetValue = serializeJni(aKey);
} catch (Exception e) { } catch (Exception e) {
Log.e(LOG_TAG, "## serialize() failed " + e.getMessage()); Log.e(LOG_TAG, "## serialize() failed " + e.getMessage());
aErrorMsg.append(e.getMessage()); aErrorMsg.append(e.getMessage());
...@@ -228,7 +229,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri ...@@ -228,7 +229,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
return pickleRetValue; return pickleRetValue;
} }
/** /**
* JNI counter part of {@link #serialize(String, StringBuffer)}. * JNI counter part of {@link #serialize(byte[], StringBuffer)}.
* @param aKey encryption key * @param aKey encryption key
* @return pickled base64 string if operation succeed, null otherwise * @return pickled base64 string if operation succeed, null otherwise
*/ */
...@@ -236,12 +237,12 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri ...@@ -236,12 +237,12 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
/** /**
* Loads an account from a pickled base64 string.<br> * Loads an account from a pickled base64 string.<br>
* See {@link #serialize(String, StringBuffer)} * See {@link #serialize(byte[], StringBuffer)}
* @param aSerializedData pickled account in a base64 string format * @param aSerializedData pickled account in a bytes buffer
* @param aKey key used to encrypted * @param aKey key used to encrypted
*/ */
@Override @Override
protected void deserialize(String aSerializedData, String aKey) throws IOException { protected void deserialize(byte[] aSerializedData, byte[] aKey) throws IOException {
if (!createNewSession()) { if (!createNewSession()) {
throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION); throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION);
} }
...@@ -250,10 +251,10 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri ...@@ -250,10 +251,10 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
try { try {
String jniError; String jniError;
if (TextUtils.isEmpty(aSerializedData) || TextUtils.isEmpty(aKey)) { if ((null == aSerializedData) || (null == aKey)) {
Log.e(LOG_TAG, "## deserialize(): invalid input parameters"); Log.e(LOG_TAG, "## deserialize(): invalid input parameters");
errorMsg.append("invalid input parameters"); errorMsg.append("invalid input parameters");
} else if (null != (jniError = deserializeJni(aSerializedData.getBytes("UTF-8"), aKey.getBytes("UTF-8")))) { } else if (null != (jniError = deserializeJni(aSerializedData, aKey))) {
errorMsg.append(jniError); errorMsg.append(jniError);
} }
} catch (Exception e) { } catch (Exception e) {
...@@ -268,9 +269,9 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri ...@@ -268,9 +269,9 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
} }
/** /**
* JNI counter part of {@link #deserialize(String, String)}. * JNI counter part of {@link #deserialize(byte[], byte[])}.
* @param aSerializedData pickled session in a base64 string format * @param aSerializedData pickled session in a base64 sbytes buffer
* @param aKey key used to encrypted in {@link #serialize(String, StringBuffer)} * @param aKey key used to encrypted in {@link #serialize(byte[], StringBuffer)}
* @return null if operation succeed, an error message if operation failed * @return null if operation succeed, an error message if operation failed
*/ */
private native String deserializeJni(byte[] aSerializedData, byte[] aKey); private native String deserializeJni(byte[] aSerializedData, byte[] aKey);
......
...@@ -117,6 +117,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser ...@@ -117,6 +117,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
/** /**
* Get a base64-encoded identifier for this session. * Get a base64-encoded identifier for this session.
* @return session identifier * @return session identifier
* @throws OlmException the failure reason
*/ */
public String sessionIdentifier() throws OlmException { public String sessionIdentifier() throws OlmException {
try { try {
...@@ -210,26 +211,26 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser ...@@ -210,26 +211,26 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
} }
/** /**
* Return the current outbound group session as a base64 serialized string.<br> * Return the current outbound group session as a base64 byte buffers.<br>
* The session is serialized and encrypted with aKey. * The session is serialized and encrypted with aKey.
* In case of failure, an error human readable * In case of failure, an error human readable
* description is provide in aErrorMsg. * description is provide in aErrorMsg.
* @param aKey encryption key * @param aKey encryption key
* @param aErrorMsg error message description * @param aErrorMsg error message description
* @return pickled base64 string if operation succeed, null otherwise * @return pickled base64 bytes buffer if operation succeed, null otherwise
*/ */
@Override @Override
protected String serialize(String aKey, StringBuffer aErrorMsg) { protected byte[] serialize(byte[] aKey, StringBuffer aErrorMsg) {
String pickleRetValue = null; byte[] pickleRetValue = null;
// sanity check // sanity check
if(null == aErrorMsg) { if(null == aErrorMsg) {
Log.e(LOG_TAG,"## serialize(): invalid parameter - aErrorMsg=null"); Log.e(LOG_TAG,"## serialize(): invalid parameter - aErrorMsg=null");
} else if(TextUtils.isEmpty(aKey)) { } else if (null == aKey) {
aErrorMsg.append("Invalid input parameters in serialize()"); aErrorMsg.append("Invalid input parameters in serialize()");
} else { } else {
try { try {
pickleRetValue = serializeJni(aKey.getBytes("UTF-8")); pickleRetValue = serializeJni(aKey);
} catch (Exception e) { } catch (Exception e) {
Log.e(LOG_TAG,"## serialize(): failed " + e.getMessage()); Log.e(LOG_TAG,"## serialize(): failed " + e.getMessage());
aErrorMsg.append(e.getMessage()); aErrorMsg.append(e.getMessage());
...@@ -238,17 +239,17 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser ...@@ -238,17 +239,17 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
return pickleRetValue; return pickleRetValue;
} }
private native String serializeJni(byte[] aKey); private native byte[] serializeJni(byte[] aKey);
/** /**
* Loads an account from a pickled base64 string.<br> * Loads an account from a pickled base64 string.<br>
* See {@link #serialize(String, StringBuffer)} * See {@link #serialize(byte[], StringBuffer)}
* @param aSerializedData pickled account in a base64 string format * @param aSerializedData pickled account in a base64 bytes buffer
* @param aKey key used to encrypted * @param aKey key used to encrypted
*/ */
@Override @Override
protected void deserialize(String aSerializedData, String aKey) throws IOException { protected void deserialize(byte[] aSerializedData, byte[] aKey) throws IOException {
if (!createNewSession()) { if (!createNewSession()) {
throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION); throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION);
} }
...@@ -257,10 +258,10 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser ...@@ -257,10 +258,10 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
try { try {
String jniError; String jniError;
if (TextUtils.isEmpty(aSerializedData) || TextUtils.isEmpty(aKey)) { if ((null == aSerializedData) || (null == aKey)) {
Log.e(LOG_TAG, "## deserialize(): invalid input parameters"); Log.e(LOG_TAG, "## deserialize(): invalid input parameters");
errorMsg.append("invalid input parameters"); errorMsg.append("invalid input parameters");
} else if (null != (jniError = deserializeJni(aSerializedData.getBytes("UTF-8"), aKey.getBytes("UTF-8")))) { } else if (null != (jniError = deserializeJni(aSerializedData, aKey))) {
errorMsg.append(jniError); errorMsg.append(jniError);
} }
} catch (Exception e) { } catch (Exception e) {
......
...@@ -336,27 +336,27 @@ public class OlmSession extends CommonSerializeUtils implements Serializable { ...@@ -336,27 +336,27 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
} }
/** /**
* Return a session as a base64 string.<br> * Return a session as a bytes buffer.<br>
* The account is serialized and encrypted with aKey. * The account is serialized and encrypted with aKey.
* In case of failure, an error human readable * In case of failure, an error human readable
* description is provide in aErrorMsg. * description is provide in aErrorMsg.
* @param aKey encryption key * @param aKey encryption key
* @param aErrorMsg error message description * @param aErrorMsg error message description
* @return pickled base64 string if operation succeed, null otherwise * @return session as a bytes buffer
*/ */
@Override @Override
protected String serialize(String aKey, StringBuffer aErrorMsg) { protected byte[] serialize(byte[] aKey, StringBuffer aErrorMsg) {
String pickleRetValue = null; byte[] pickleRetValue = null;
// sanity check // sanity check
if(null == aErrorMsg) { if(null == aErrorMsg) {
Log.e(LOG_TAG,"## serializeDataWithKey(): invalid parameter - aErrorMsg=null"); Log.e(LOG_TAG,"## serializeDataWithKey(): invalid parameter - aErrorMsg=null");
} else if(TextUtils.isEmpty(aKey)) { } else if (null == aKey) {
aErrorMsg.append("Invalid input parameters in serializeDataWithKey()"); aErrorMsg.append("Invalid input parameters in serializeDataWithKey()");
} else { } else {
aErrorMsg.setLength(0); aErrorMsg.setLength(0);
try { try {
pickleRetValue = serializeJni(aKey.getBytes("UTF-8")); pickleRetValue = serializeJni(aKey);
} catch (Exception e) { } catch (Exception e) {
Log.e(LOG_TAG,"## serializeDataWithKey(): failed " + e.getMessage()); Log.e(LOG_TAG,"## serializeDataWithKey(): failed " + e.getMessage());
aErrorMsg.append(e.getMessage()); aErrorMsg.append(e.getMessage());
...@@ -365,16 +365,16 @@ public class OlmSession extends CommonSerializeUtils implements Serializable { ...@@ -365,16 +365,16 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
return pickleRetValue; return pickleRetValue;
} }
private native String serializeJni(byte[] aKey); private native byte[] serializeJni(byte[] aKey);
/** /**
* Loads an account from a pickled base64 string.<br> * Loads an account from a pickled base64 string.<br>
* See {@link #serialize(String, StringBuffer)} * See {@link #serialize(byte[], StringBuffer)}
* @param aSerializedData pickled account in a base64 string format * @param aSerializedData pickled account in a base64 string format
* @param aKey key used to encrypted * @param aKey key used to encrypted
*/ */
@Override @Override
protected void deserialize(String aSerializedData, String aKey) throws IOException { protected void deserialize(byte[] aSerializedData, byte[] aKey) throws IOException {
if (!createNewSession()) { if (!createNewSession()) {
throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION); throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION);
} }
...@@ -383,10 +383,10 @@ public class OlmSession extends CommonSerializeUtils implements Serializable { ...@@ -383,10 +383,10 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
try { try {
String jniError; String jniError;
if (TextUtils.isEmpty(aSerializedData) || TextUtils.isEmpty(aKey)) { if ((null == aSerializedData) || (null == aKey)) {
Log.e(LOG_TAG, "## deserialize(): invalid input parameters"); Log.e(LOG_TAG, "## deserialize(): invalid input parameters");
errorMsg.append("invalid input parameters"); errorMsg.append("invalid input parameters");
} else if (null != (jniError = deserializeJni(aSerializedData.getBytes("UTF-8"), aKey.getBytes("UTF-8")))) { } else if (null != (jniError = deserializeJni(aSerializedData, aKey))) {
errorMsg.append(jniError); errorMsg.append(jniError);
} }
} catch (Exception e) { } catch (Exception e) {
......
...@@ -135,13 +135,13 @@ public class OlmUtility { ...@@ -135,13 +135,13 @@ public class OlmUtility {
/** /**
* Helper method to compute a string based on random integers. * Helper method to compute a string based on random integers.
* @return string containing randoms integer values * @return bytes buffer containing randoms integer values
*/ */
public static String getRandomKey() { public static byte[] getRandomKey() {
SecureRandom secureRandom = new SecureRandom(); SecureRandom secureRandom = new SecureRandom();
byte[] buffer = new byte[RANDOM_KEY_SIZE]; byte[] buffer = new byte[RANDOM_KEY_SIZE];
secureRandom.nextBytes(buffer); secureRandom.nextBytes(buffer);
return new String(buffer); return buffer;
} }
/** /**
......
...@@ -558,7 +558,6 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thi ...@@ -558,7 +558,6 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thi
size_t pickledLength = olm_pickle_account_length(accountPtr); size_t pickledLength = olm_pickle_account_length(accountPtr);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer); size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
LOGD(" ## serializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength)); 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)); void *pickledPtr = malloc((pickledLength+1)*sizeof(uint8_t));
...@@ -586,8 +585,8 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thi ...@@ -586,8 +585,8 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thi
LOGD(" ## serializeJni(): 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); pickledDataRetValue = env->NewByteArray(pickledLength);
env->SetByteArrayRegion(pickledDataRetValue, 0 , pickledLength+1, (jbyte*)pickledPtr);