diff options
Diffstat (limited to 'java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java')
-rw-r--r-- | java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java | 53 |
1 files changed, 15 insertions, 38 deletions
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 501d660..6f27507 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 @@ -34,7 +34,7 @@ import java.io.Serializable; * * <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>. */ -public class OlmInboundGroupSession implements Serializable { +public class OlmInboundGroupSession extends CommonSerializeUtils implements Serializable { private static final long serialVersionUID = -772028491251653253L; private static final String LOG_TAG = "OlmInboundGroupSession"; @@ -139,21 +139,7 @@ public class OlmInboundGroupSession implements Serializable { * @throws IOException exception */ private void writeObject(ObjectOutputStream aOutStream) throws IOException { - aOutStream.defaultWriteObject(); - - // generate serialization key - String key = OlmUtility.getRandomKey(); - - // compute pickle string - StringBuffer errorMsg = new StringBuffer(); - String pickledData = serializeDataWithKey(key, errorMsg); - - if(null == pickledData) { - throw new OlmException(OlmException.EXCEPTION_CODE_INBOUND_GROUP_SESSION_SERIALIZATION, String.valueOf(errorMsg)); - } else { - aOutStream.writeObject(key); - aOutStream.writeObject(pickledData); - } + serializeObject(aOutStream); } /** @@ -163,28 +149,17 @@ public class OlmInboundGroupSession implements Serializable { * @throws ClassNotFoundException exception */ private void readObject(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)) { - throw new OlmException(OlmException.EXCEPTION_CODE_INBOUND_GROUP_SESSION_DESERIALIZATION, OlmException.EXCEPTION_MSG_INVALID_PARAMS_DESERIALIZATION+" key"); - - } else if(TextUtils.isEmpty(pickledData)) { - throw new OlmException(OlmException.EXCEPTION_CODE_INBOUND_GROUP_SESSION_DESERIALIZATION, OlmException.EXCEPTION_MSG_INVALID_PARAMS_DESERIALIZATION+" pickle"); - - } else if(!createNewSession()) { - throw new OlmException(OlmException.EXCEPTION_CODE_INBOUND_GROUP_SESSION_DESERIALIZATION, OlmException.EXCEPTION_MSG_INIT_NEW_ACCOUNT_DESERIALIZATION); + deserializeObject(aInStream); + } - } else if(!initWithSerializedData(pickledData, key, errorMsg)) { - releaseSession(); // prevent memory leak - throw new OlmException(OlmException.EXCEPTION_CODE_INBOUND_GROUP_SESSION_DESERIALIZATION, String.valueOf(errorMsg)); + @Override + protected boolean createNewObjectFromSerialization() { + return createNewSession(); + } - } else { - Log.d(LOG_TAG,"## readObject(): success"); - } + @Override + protected void releaseObjectFromSerialization() { + releaseSession(); } /** @@ -196,7 +171,8 @@ public class OlmInboundGroupSession implements Serializable { * @param aErrorMsg error message description * @return pickled base64 string if operation succeed, null otherwise */ - private String serializeDataWithKey(String aKey, StringBuffer aErrorMsg) { + @Override + protected String serializeDataWithKey(String aKey, StringBuffer aErrorMsg) { String pickleRetValue = null; // sanity check @@ -228,7 +204,8 @@ public class OlmInboundGroupSession implements Serializable { * @param aErrorMsg error message description * @return true if operation succeed, false otherwise */ - private boolean initWithSerializedData(String aSerializedData, String aKey, StringBuffer aErrorMsg) { + @Override + protected boolean initWithSerializedData(String aSerializedData, String aKey, StringBuffer aErrorMsg) { boolean retCode = false; String jniError; |