Skip to content

Commit

Permalink
Introduce PublicStorageProvider (openmls#1639)
Browse files Browse the repository at this point in the history
Co-authored-by: Konrad Kohbrok <[email protected]>
  • Loading branch information
raphaelrobert and kkohbrok authored Aug 8, 2024
1 parent e543c63 commit c69910e
Show file tree
Hide file tree
Showing 10 changed files with 290 additions and 18 deletions.
5 changes: 2 additions & 3 deletions openmls/src/group/public_group/builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use openmls_traits::{
crypto::OpenMlsCrypto, signatures::Signer, types::Ciphersuite, OpenMlsProvider,
};
use openmls_traits::{crypto::OpenMlsCrypto, signatures::Signer, types::Ciphersuite};

use super::{errors::PublicGroupBuildError, PublicGroup};
use crate::{
Expand All @@ -11,6 +9,7 @@ use crate::{
key_packages::Lifetime,
messages::ConfirmationTag,
schedule::CommitSecret,
storage::OpenMlsProvider,
treesync::{
node::{encryption_keys::EncryptionKeyPair, leaf_node::Capabilities},
TreeSync,
Expand Down
14 changes: 7 additions & 7 deletions openmls/src/group/public_group/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use crate::{
ConfirmationTag, PathSecret,
},
schedule::CommitSecret,
storage::{OpenMlsProvider, StorageProvider},
storage::{OpenMlsProvider, PublicStorageProvider},
treesync::{
errors::{DerivePathError, TreeSyncFromNodesError},
node::{
Expand Down Expand Up @@ -355,10 +355,10 @@ impl PublicGroup {
/// existing group, both inside [`PublicGroup`] and in [`CoreGroup`].
///
/// [`CoreGroup`]: crate::group::core_group::CoreGroup
pub(crate) fn store<Storage: StorageProvider>(
pub(crate) fn store<Storage: PublicStorageProvider>(
&self,
storage: &Storage,
) -> Result<(), Storage::Error> {
) -> Result<(), Storage::PublicError> {
let group_id = self.group_context.group_id();
storage.write_tree(group_id, self.treesync())?;
storage.write_confirmation_tag(group_id, self.confirmation_tag())?;
Expand All @@ -371,10 +371,10 @@ impl PublicGroup {
}

/// Deletes the [`PublicGroup`] from storage.
pub(crate) fn delete<Storage: StorageProvider>(
pub(crate) fn delete<Storage: PublicStorageProvider>(
&self,
storage: &Storage,
) -> Result<(), Storage::Error> {
) -> Result<(), Storage::PublicError> {
storage.delete_tree(self.group_id())?;
storage.delete_confirmation_tag(self.group_id())?;
storage.delete_context(self.group_id())?;
Expand All @@ -384,10 +384,10 @@ impl PublicGroup {
}

/// Loads the [`PublicGroup`] corresponding to a [`GroupId`] from storage.
pub fn load<Storage: StorageProvider>(
pub fn load<Storage: PublicStorageProvider>(
storage: &Storage,
group_id: &GroupId,
) -> Result<Option<Self>, Storage::Error> {
) -> Result<Option<Self>, Storage::PublicError> {
let treesync = storage.treesync(group_id)?;
let proposals: Vec<(ProposalRef, QueuedProposal)> = storage.queued_proposals(group_id)?;
let group_context = storage.group_context(group_id)?;
Expand Down
5 changes: 2 additions & 3 deletions openmls/src/group/public_group/staged_commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::{
StagedCommit,
},
messages::{proposals::ProposalOrRef, Commit},
storage::StorageProvider,
};

#[derive(Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -274,11 +273,11 @@ impl PublicGroup {
}

/// Merges a [StagedCommit] into the public group state.
pub fn merge_commit<Storage: StorageProvider>(
pub fn merge_commit<Storage: PublicStorageProvider>(
&mut self,
storage: &Storage,
staged_commit: StagedCommit,
) -> Result<(), MergeCommitError<Storage::Error>> {
) -> Result<(), MergeCommitError<Storage::PublicError>> {
match staged_commit.into_state() {
StagedCommitState::PublicState(staged_state) => {
self.merge_diff(staged_state.staged_diff);
Expand Down
12 changes: 12 additions & 0 deletions openmls/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,20 @@ pub mod kat_storage_stability;
/// Throughout the code, this one should be used instead of `openmls_traits::storage::StorageProvider`.
pub trait StorageProvider: openmls_traits::storage::StorageProvider<CURRENT_VERSION> {}

/// A convenience trait for the current version of the public storage.
/// Throughout the code, this one should be used instead of `openmls_traits::public_storage::PublicStorageProvider`.
pub trait PublicStorageProvider:
openmls_traits::public_storage::PublicStorageProvider<CURRENT_VERSION>
{
}

impl<P: openmls_traits::storage::StorageProvider<CURRENT_VERSION>> StorageProvider for P {}

impl<P: openmls_traits::public_storage::PublicStorageProvider<CURRENT_VERSION>>
PublicStorageProvider for P
{
}

/// A convenience trait for the OpenMLS provider that defines the storage provider
/// for the current version of storage.
/// Throughout the code, this one should be used instead of `openmls_traits::OpenMlsProvider`.
Expand Down
3 changes: 2 additions & 1 deletion openmls/src/treesync/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::collections::HashSet;

use log::debug;
use openmls_traits::crypto::OpenMlsCrypto;
use openmls_traits::{signatures::Signer, types::Ciphersuite, OpenMlsProvider};
use openmls_traits::{signatures::Signer, types::Ciphersuite};
use serde::{Deserialize, Serialize};

use super::node::leaf_node::UpdateLeafNodeParams;
Expand All @@ -48,6 +48,7 @@ use crate::{
error::LibraryError,
messages::PathSecret,
schedule::CommitSecret,
storage::OpenMlsProvider,
treesync::RatchetTree,
};

Expand Down
4 changes: 3 additions & 1 deletion openmls/src/treesync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use openmls_traits::{
crypto::OpenMlsCrypto,
signatures::Signer,
types::{Ciphersuite, CryptoError},
OpenMlsProvider,
};
use serde::{Deserialize, Serialize};
use thiserror::Error;
Expand Down Expand Up @@ -62,6 +61,7 @@ use crate::{
key_packages::Lifetime,
messages::{PathSecret, PathSecretError},
schedule::CommitSecret,
storage::OpenMlsProvider,
};

// Private
Expand Down Expand Up @@ -731,6 +731,8 @@ mod test {
ciphersuite: Ciphersuite,
provider: &impl OpenMlsProvider,
) {
use openmls_traits::OpenMlsProvider;

let (key_package, _, _) = crate::key_packages::tests::key_package(ciphersuite, provider);
let node_in = NodeIn::from(Node::LeafNode(LeafNode::from(key_package)));
let tests = [
Expand Down
3 changes: 1 addition & 2 deletions openmls/src/treesync/node/encryption_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ use openmls_traits::{
crypto::OpenMlsCrypto,
storage::{StorageProvider as StorageProviderTrait, CURRENT_VERSION},
types::{Ciphersuite, HpkeCiphertext, HpkeKeyPair},
OpenMlsProvider,
};
use serde::{Deserialize, Serialize};
use tls_codec::{TlsDeserialize, TlsDeserializeBytes, TlsSerialize, TlsSize, VLBytes};

use crate::{
ciphersuite::{hpke, HpkePrivateKey, HpkePublicKey, Secret},
error::LibraryError,
storage::StorageProvider,
storage::{OpenMlsProvider, StorageProvider},
};

/// [`EncryptionKey`] contains an HPKE public key that allows the encryption of
Expand Down
Loading

0 comments on commit c69910e

Please sign in to comment.