Skip to content

Commit

Permalink
Move public methods back into their original place
Browse files Browse the repository at this point in the history
  • Loading branch information
Johennes committed Apr 19, 2024
1 parent b68fc06 commit e6722e4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 41 deletions.
25 changes: 13 additions & 12 deletions src/megolm/group_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ impl GroupSession {
pub fn from_pickle(pickle: GroupSessionPickle) -> Self {
pickle.into()
}

#[cfg(feature = "libolm-compat")]
pub fn from_libolm_pickle(
pickle: &str,
pickle_key: &[u8],
) -> Result<Self, crate::LibolmPickleError> {
use crate::{megolm::group_session::libolm_compat::Pickle, utilities::unpickle_libolm};

const PICKLE_VERSION: u32 = 1;
unpickle_libolm::<Pickle, _>(pickle, pickle_key, PICKLE_VERSION)
}
}

#[cfg(feature = "libolm-compat")]
Expand All @@ -150,13 +161,13 @@ mod libolm_compat {
use super::GroupSession;
use crate::{
megolm::{libolm::LibolmRatchetPickle, SessionConfig},
utilities::{unpickle_libolm, LibolmEd25519Keypair},
utilities::LibolmEd25519Keypair,
Ed25519Keypair,
};

#[derive(Zeroize, Decode)]
#[zeroize(drop)]
struct Pickle {
pub(super) struct Pickle {
version: u32,
ratchet: LibolmRatchetPickle,
ed25519_keypair: LibolmEd25519Keypair,
Expand All @@ -176,16 +187,6 @@ mod libolm_compat {
Ok(Self { ratchet, signing_key, config: SessionConfig::version_1() })
}
}

impl GroupSession {
pub fn from_libolm_pickle(
pickle: &str,
pickle_key: &[u8],
) -> Result<Self, crate::LibolmPickleError> {
const PICKLE_VERSION: u32 = 1;
unpickle_libolm::<Pickle, _>(pickle, pickle_key, PICKLE_VERSION)
}
}
}

/// A format suitable for serialization which implements [`serde::Serialize`]
Expand Down
26 changes: 14 additions & 12 deletions src/megolm/inbound_group_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,19 @@ impl InboundGroupSession {
pub fn from_pickle(pickle: InboundGroupSessionPickle) -> Self {
Self::from(pickle)
}

#[cfg(feature = "libolm-compat")]
pub fn from_libolm_pickle(
pickle: &str,
pickle_key: &[u8],
) -> Result<Self, crate::LibolmPickleError> {
use crate::{
megolm::inbound_group_session::libolm_compat::Pickle, utilities::unpickle_libolm,
};

const PICKLE_VERSION: u32 = 2;
unpickle_libolm::<Pickle, _>(pickle, pickle_key, PICKLE_VERSION)
}
}

#[cfg(feature = "libolm-compat")]
Expand All @@ -374,13 +387,12 @@ mod libolm_compat {
use super::InboundGroupSession;
use crate::{
megolm::{libolm::LibolmRatchetPickle, SessionConfig},
utilities::unpickle_libolm,
Ed25519PublicKey,
};

#[derive(Zeroize, Decode)]
#[zeroize(drop)]
struct Pickle {
pub(super) struct Pickle {
version: u32,
initial_ratchet: LibolmRatchetPickle,
latest_ratchet: LibolmRatchetPickle,
Expand Down Expand Up @@ -410,16 +422,6 @@ mod libolm_compat {
})
}
}

impl InboundGroupSession {
pub fn from_libolm_pickle(
pickle: &str,
pickle_key: &[u8],
) -> Result<Self, crate::LibolmPickleError> {
const PICKLE_VERSION: u32 = 2;
unpickle_libolm::<Pickle, _>(pickle, pickle_key, PICKLE_VERSION)
}
}
}

/// A format suitable for serialization which implements [`serde::Serialize`]
Expand Down
34 changes: 17 additions & 17 deletions src/olm/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,22 @@ impl Session {
pub fn from_pickle(pickle: SessionPickle) -> Self {
pickle.into()
}

/// Create a [`Session`] object by unpickling a session pickle in libolm
/// legacy pickle format.
///
/// Such pickles are encrypted and need to first be decrypted using
/// `pickle_key`.
#[cfg(feature = "libolm-compat")]
pub fn from_libolm_pickle(
pickle: &str,
pickle_key: &[u8],
) -> Result<Self, crate::LibolmPickleError> {
use crate::{olm::session::libolm_compat::Pickle, utilities::unpickle_libolm};

const PICKLE_VERSION: u32 = 1;
unpickle_libolm::<Pickle, _>(pickle, pickle_key, PICKLE_VERSION)
}
}

#[cfg(feature = "libolm-compat")]
Expand All @@ -336,7 +352,6 @@ mod libolm_compat {
use crate::{
olm::{SessionConfig, SessionKeys},
types::Curve25519SecretKey,
utilities::unpickle_libolm,
Curve25519PublicKey,
};

Expand Down Expand Up @@ -387,7 +402,7 @@ mod libolm_compat {
}

#[derive(Decode)]
struct Pickle {
pub(super) struct Pickle {
#[allow(dead_code)]
version: u32,
#[allow(dead_code)]
Expand Down Expand Up @@ -464,21 +479,6 @@ mod libolm_compat {
}
}
}

impl Session {
/// Create a [`Session`] object by unpickling a session pickle in libolm
/// legacy pickle format.
///
/// Such pickles are encrypted and need to first be decrypted using
/// `pickle_key`.
pub fn from_libolm_pickle(
pickle: &str,
pickle_key: &[u8],
) -> Result<Self, crate::LibolmPickleError> {
const PICKLE_VERSION: u32 = 1;
unpickle_libolm::<Pickle, _>(pickle, pickle_key, PICKLE_VERSION)
}
}
}

/// A format suitable for serialization which implements [`serde::Serialize`]
Expand Down

0 comments on commit e6722e4

Please sign in to comment.