Skip to content

Commit

Permalink
Allow PNI in PendingMember
Browse files Browse the repository at this point in the history
  • Loading branch information
rubdos committed Oct 12, 2024
1 parent 65b51db commit 9a95d3a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
9 changes: 5 additions & 4 deletions libsignal-service/src/groups_v2/model.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{convert::TryFrom, convert::TryInto};

use derivative::Derivative;
use libsignal_protocol::ServiceId;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use zkgroup::profiles::ProfileKey;
Expand Down Expand Up @@ -30,15 +31,15 @@ impl PartialEq for Member {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PendingMember {
pub uuid: Uuid,
pub service_id: ServiceId,
pub role: Role,
pub added_by_uuid: Uuid,
pub timestamp: u64,
}

#[derive(Derivative, Clone, Deserialize, Serialize)]
#[derive(Derivative, Clone)]
#[derivative(Debug)]
pub struct RequestingMember {
pub uuid: Uuid,
Expand Down Expand Up @@ -69,7 +70,7 @@ pub struct AccessControl {
pub add_from_invite_link: AccessRequired,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq)]
pub struct Group {
pub title: String,
pub avatar: String,
Expand Down
17 changes: 15 additions & 2 deletions libsignal-service/src/groups_v2/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ impl From<zkgroup::ZkGroupVerificationFailure> for GroupDecodingError {
}

impl GroupOperations {
fn decrypt_service_id(
&self,
ciphertext: &[u8],
) -> Result<ServiceId, GroupDecodingError> {
match self
.group_secret_params
.decrypt_service_id(bincode::deserialize(ciphertext)?)?
{
ServiceId::Aci(aci) => Ok(ServiceId::from(aci)),
ServiceId::Pni(pni) => Ok(ServiceId::from(pni)),
}
}

fn decrypt_aci(
&self,
ciphertext: &[u8],
Expand Down Expand Up @@ -131,11 +144,11 @@ impl GroupOperations {
) -> Result<PendingMember, GroupDecodingError> {
let inner_member =
member.member.ok_or(GroupDecodingError::WrongBlob)?;
let aci = self.decrypt_aci(&inner_member.user_id)?;
let service_id = self.decrypt_service_id(&inner_member.user_id)?;
let added_by_uuid = self.decrypt_aci(&member.added_by_user_id)?;

Ok(PendingMember {
uuid: aci.into(),
service_id,
role: inner_member.role.try_into()?,
added_by_uuid: added_by_uuid.into(),
timestamp: member.timestamp,
Expand Down

0 comments on commit 9a95d3a

Please sign in to comment.