Skip to content

Commit

Permalink
aad bytewrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed May 10, 2024
1 parent 6bc9d88 commit 6ba1a80
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions memory_storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,11 @@ impl StorageProvider<CURRENT_VERSION> for MemoryStorage {
group_id: &GroupId,
) -> Result<ByteWrapper, Self::Error> {
let key = serde_json::to_vec(group_id)?;
self.read(AAD_LABEL, &key)
match self.read(AAD_LABEL, &key) {
Ok(Some(data)) => Ok(data),
Ok(None) => Ok(ByteWrapper::from(Vec::new())),
Err(e) => Err(e),
}
}

fn write_aad<
Expand All @@ -889,7 +893,7 @@ impl StorageProvider<CURRENT_VERSION> for MemoryStorage {
aad: &ByteWrapper,
) -> Result<(), Self::Error> {
let key = serde_json::to_vec(group_id)?;
self.write::<CURRENT_VERSION>(AAD_LABEL, &key, aad.to_vec())
self.write::<CURRENT_VERSION>(AAD_LABEL, &key, serde_json::to_vec(aad).unwrap())
}

fn delete_aad<GroupId: traits::GroupId<CURRENT_VERSION>>(
Expand Down
12 changes: 12 additions & 0 deletions openmls/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ struct ByteWrapper {
data: Vec<u8>,
}

impl ByteWrapper {
fn from(data: Vec<u8>) -> Self {
ByteWrapper { data }
}
}

impl From<Vec<u8>> for ByteWrapper {
fn from(data: Vec<u8>) -> Self {
ByteWrapper { data }
}
}

impl Entity<CURRENT_VERSION> for ByteWrapper {}
impl traits::ByteWrapper<CURRENT_VERSION> for ByteWrapper {}

Expand Down
1 change: 1 addition & 0 deletions traits/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ pub mod traits {
pub trait EpochKey<const VERSION: u16>: Key<VERSION> {}

// traits for entity, one per type
pub trait ByteWrapper<const VERSION: u16>: Entity<VERSION> {}
pub trait QueuedProposal<const VERSION: u16>: Entity<VERSION> {}
pub trait TreeSync<const VERSION: u16>: Entity<VERSION> {}
pub trait GroupContext<const VERSION: u16>: Entity<VERSION> {}
Expand Down

0 comments on commit 6ba1a80

Please sign in to comment.