From 00138f7ae5d2a2195d78a814fb1e588fa5bc4b32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 18 Mar 2020 09:38:41 +0100 Subject: [PATCH] crypto: Expose the pickling methods for the account. --- src/crypto/olm.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/crypto/olm.rs b/src/crypto/olm.rs index 8a3fabae..1f893d39 100644 --- a/src/crypto/olm.rs +++ b/src/crypto/olm.rs @@ -15,6 +15,8 @@ use std::fmt; use olm_rs::account::{IdentityKeys, OlmAccount, OneTimeKeys}; +use olm_rs::errors::OlmAccountError; +use olm_rs::PicklingMode; pub struct Account { inner: OlmAccount, @@ -82,6 +84,25 @@ impl Account { pub fn sign(&self, string: &str) -> String { self.inner.sign(string) } + + pub fn pickle(&self, pickling_mode: PicklingMode) -> String { + self.inner.pickle(pickling_mode) + } + + pub fn from_pickle( + pickle: String, + pickling_mode: PicklingMode, + shared: bool, + ) -> Result { + let acc = OlmAccount::unpickle(pickle, pickling_mode)?; + Ok(Account { inner: acc, shared }) + } +} + +impl PartialEq for Account { + fn eq(&self, other: &Self) -> bool { + self.identity_keys() == other.identity_keys() + } } #[cfg(test)]