forked from signalapp/libsignal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backup: Move GroupData-related processing to a new file
- Loading branch information
1 parent
c155166
commit 9f6ceee
Showing
2 changed files
with
62 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// Copyright (C) 2024 Signal Messenger, LLC. | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
// | ||
|
||
use zkgroup::GroupMasterKeyBytes; | ||
|
||
use crate::backup::recipient::RecipientError; | ||
use crate::backup::serialize; | ||
use crate::proto::backup as proto; | ||
|
||
#[derive(Debug, serde::Serialize)] | ||
#[cfg_attr(test, derive(PartialEq))] | ||
pub struct GroupData { | ||
pub master_key: GroupMasterKeyBytes, | ||
pub whitelisted: bool, | ||
pub hide_story: bool, | ||
#[serde(serialize_with = "serialize::enum_as_string")] | ||
pub story_send_mode: proto::group::StorySendMode, | ||
#[serde(serialize_with = "serialize::optional_proto_message_as_bytes")] | ||
pub snapshot: Option<Box<proto::group::GroupSnapshot>>, | ||
} | ||
|
||
impl TryFrom<proto::Group> for GroupData { | ||
type Error = RecipientError; | ||
fn try_from(value: proto::Group) -> Result<Self, Self::Error> { | ||
let proto::Group { | ||
masterKey, | ||
whitelisted, | ||
hideStory, | ||
storySendMode, | ||
snapshot, | ||
special_fields: _, | ||
} = value; | ||
|
||
let master_key = masterKey | ||
.try_into() | ||
.map_err(|_| RecipientError::InvalidMasterKey)?; | ||
|
||
let story_send_mode = match storySendMode.enum_value_or_default() { | ||
s @ (proto::group::StorySendMode::DEFAULT | ||
| proto::group::StorySendMode::DISABLED | ||
| proto::group::StorySendMode::ENABLED) => s, | ||
}; | ||
|
||
// TODO consider additional group snapshot validation. | ||
let snapshot = snapshot.0; | ||
|
||
Ok(GroupData { | ||
master_key, | ||
whitelisted, | ||
hide_story: hideStory, | ||
story_send_mode, | ||
snapshot, | ||
}) | ||
} | ||
} |