Skip to content

Commit

Permalink
fix: Remove cached is_e2ei_capable flag
Browse files Browse the repository at this point in the history
  • Loading branch information
OtaK committed Feb 21, 2024
1 parent b998d03 commit 02fde65
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 29 deletions.
12 changes: 3 additions & 9 deletions crypto/src/e2e_identity/rotate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,15 +693,9 @@ pub mod tests {
.collect::<Vec<_>>();
assert_eq!(all_credentials.len(), 2);

let client = Client::load(
&alice_central.mls_central.mls_backend,
&cid,
all_credentials,
scs,
matches!(case.credential_type, MlsCredentialType::X509),
)
.await
.unwrap();
let client = Client::load(&alice_central.mls_central.mls_backend, &cid, all_credentials, scs)
.await
.unwrap();
alice_central.mls_central.mls_client = Some(client);

// Verify that Alice has the same credentials
Expand Down
27 changes: 7 additions & 20 deletions crypto/src/mls/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ pub struct Client {
id: ClientId,
pub(crate) identities: ClientIdentities,
keypackage_lifetime: std::time::Duration,
is_e2ei_capable: bool,
}

impl Client {
Expand All @@ -74,8 +73,6 @@ impl Client {
backend: &MlsCryptoProvider,
nb_key_package: usize,
) -> CryptoResult<Self> {
let is_e2ei_capable = matches!(identifier, ClientIdentifier::X509(_));

let id = identifier.get_id()?;

let credentials = backend
Expand All @@ -97,15 +94,15 @@ impl Client {
.iter()
.map(|cs| cs.signature_algorithm())
.collect::<HashSet<_>>();
match Self::load(backend, id.as_ref(), credentials, signature_schemes, is_e2ei_capable).await {
match Self::load(backend, id.as_ref(), credentials, signature_schemes).await {
Ok(client) => client,
Err(CryptoError::ClientSignatureNotFound) => {
Self::generate(identifier, backend, ciphersuites, nb_key_package, is_e2ei_capable).await?
Self::generate(identifier, backend, ciphersuites, nb_key_package).await?
}
Err(e) => return Err(e),
}
} else {
Self::generate(identifier, backend, ciphersuites, nb_key_package, is_e2ei_capable).await?
Self::generate(identifier, backend, ciphersuites, nb_key_package).await?
};

Ok(client)
Expand Down Expand Up @@ -194,7 +191,6 @@ impl Client {
id: client_id.clone(),
identities: ClientIdentities::new(stored_skp.len()),
keypackage_lifetime: KEYPACKAGE_DEFAULT_LIFETIME,
is_e2ei_capable: false,
};

let id = &client_id;
Expand Down Expand Up @@ -242,7 +238,6 @@ impl Client {
backend: &MlsCryptoProvider,
ciphersuites: &[MlsCiphersuite],
nb_key_package: usize,
is_e2ei_capable: bool,
) -> CryptoResult<Self> {
let id = identifier.get_id()?;
let signature_schemes = ciphersuites
Expand All @@ -253,7 +248,6 @@ impl Client {
id: id.into_owned(),
identities: ClientIdentities::new(signature_schemes.len()),
keypackage_lifetime: KEYPACKAGE_DEFAULT_LIFETIME,
is_e2ei_capable,
};

let identities = identifier.generate_credential_bundles(backend, signature_schemes)?;
Expand Down Expand Up @@ -283,7 +277,6 @@ impl Client {
id: &ClientId,
mut credentials: Vec<(Credential, u64)>,
signature_schemes: HashSet<SignatureScheme>,
is_e2ei_capable: bool,
) -> CryptoResult<Self> {
let mut identities = ClientIdentities::new(signature_schemes.len());

Expand Down Expand Up @@ -336,7 +329,6 @@ impl Client {
id: id.clone(),
identities,
keypackage_lifetime: KEYPACKAGE_DEFAULT_LIFETIME,
is_e2ei_capable,
})
}

Expand Down Expand Up @@ -403,7 +395,9 @@ impl Client {

/// Returns whether this client is E2EI capable
pub fn is_e2ei_capable(&self) -> bool {
self.is_e2ei_capable
self.identities
.iter()
.any(|(_, cred)| cred.credential().credential_type() == CredentialType::X509)
}

pub(crate) async fn get_most_recent_or_create_credential_bundle(
Expand Down Expand Up @@ -480,14 +474,7 @@ impl Client {
} else {
0
};
Self::generate(
identity,
backend,
&[case.ciphersuite()],
nb_key_package,
matches!(case.credential_type, MlsCredentialType::X509),
)
.await
Self::generate(identity, backend, &[case.ciphersuite()], nb_key_package).await
}

pub async fn find_keypackages(
Expand Down

0 comments on commit 02fde65

Please sign in to comment.