From 0a6a5a5caf0c15998b819fd82dd5dfaa3534b74c Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 7 Apr 2022 20:19:40 +0200 Subject: [PATCH] Add public pickle/unpickle methods to java bindings --- .../matrix/olm/OlmInboundGroupSession.java | 25 +++++++++++++++++++ .../matrix/olm/OlmOutboundGroupSession.java | 24 ++++++++++++++++++ .../main/java/org/matrix/olm/OlmSession.java | 25 +++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/android/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java b/android/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java index 2fc81ef..4397ed4 100644 --- a/android/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java +++ b/android/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java @@ -369,4 +369,29 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri * @return the deserialized session **/ private native long deserializeJni(byte[] aSerializedData, byte[] aKey); + + /** + * Return a pickled inbound group session as a bytes buffer.
+ * 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 the pickled inbound group session as bytes buffer + */ + public byte[] pickle(byte[] aKey, StringBuffer aErrorMsg) { + return serialize(aKey, aErrorMsg); + } + + /** + * Loads an inbound group session from a pickled bytes buffer.
+ * See {@link #serialize(byte[], StringBuffer)} + * @param aSerializedData bytes buffer + * @param aKey key used to encrypted + * @exception Exception the exception + */ + public void unpickle(byte[] aSerializedData, byte[] aKey) throws Exception { + deserialize(aSerializedData, aKey); + } + } diff --git a/android/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java b/android/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java index 55732fe..fa9f7a4 100644 --- a/android/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java +++ b/android/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java @@ -293,4 +293,28 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser **/ private native long deserializeJni(byte[] aSerializedData, byte[] aKey); + /** + * Return a pickled outbound group session as a bytes buffer.
+ * 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 the pickled outbound group session as bytes buffer + */ + public byte[] pickle(byte[] aKey, StringBuffer aErrorMsg) { + return serialize(aKey, aErrorMsg); + } + + /** + * Loads an outbound group session from a pickled bytes buffer.
+ * See {@link #serialize(byte[], StringBuffer)} + * @param aSerializedData bytes buffer + * @param aKey key used to encrypted + * @exception Exception the exception + */ + public void unpickle(byte[] aSerializedData, byte[] aKey) throws Exception { + deserialize(aSerializedData, aKey); + } + } diff --git a/android/olm-sdk/src/main/java/org/matrix/olm/OlmSession.java b/android/olm-sdk/src/main/java/org/matrix/olm/OlmSession.java index 5669ba1..0e22a80 100644 --- a/android/olm-sdk/src/main/java/org/matrix/olm/OlmSession.java +++ b/android/olm-sdk/src/main/java/org/matrix/olm/OlmSession.java @@ -465,5 +465,30 @@ public class OlmSession extends CommonSerializeUtils implements Serializable { * @return the deserialized session **/ private native long deserializeJni(byte[] aSerializedData, byte[] aKey); + + /** + * Return a pickled session as a bytes buffer.
+ * 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 the pickled session as bytes buffer + */ + public byte[] pickle(byte[] aKey, StringBuffer aErrorMsg) { + return serialize(aKey, aErrorMsg); + } + + /** + * Loads a session from a pickled bytes buffer.
+ * See {@link #serialize(byte[], StringBuffer)} + * @param aSerializedData bytes buffer + * @param aKey key used to encrypted + * @exception Exception the exception + */ + public void unpickle(byte[] aSerializedData, byte[] aKey) throws Exception { + deserialize(aSerializedData, aKey); + } + }