Skip to content

Commit d5d6bab

Browse files
refactor: remove Idetities::ensure_distinct()
Because credentials are now always distinct.
1 parent 66f6979 commit d5d6bab

File tree

2 files changed

+1
-60
lines changed

2 files changed

+1
-60
lines changed

crypto/src/mls/session/credential.rs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -60,38 +60,12 @@ impl Session {
6060
&self,
6161
mut credential: Credential,
6262
) -> Result<Arc<Credential>> {
63-
let credential_ref = credential
63+
let _credential_ref = credential
6464
.save(&self.crypto_provider.keystore())
6565
.await
6666
.map_err(RecursiveError::mls_credential("saving credential"))?;
6767

6868
let guard = self.inner.upgradable_read().await;
69-
let inner = guard.as_ref().ok_or(Error::MlsNotInitialized)?;
70-
71-
// failfast before loading the cache if we know already that this credential ref can't be added to the identity
72-
// set
73-
let distinct_result = inner.identities.ensure_distinct(
74-
credential_ref.signature_scheme(),
75-
credential_ref.r#type(),
76-
credential_ref.earliest_validity(),
77-
);
78-
if let Err(err) = distinct_result {
79-
// first clean up by removing the credential we just saved
80-
// otherwise, we'll have nondeterministic results when we load
81-
//
82-
// TODO this depends for correctness that no two added credentials have the same keypair;
83-
// if this happens for a keypair which was removed, we'll remove the (old, used) keypair
84-
// and forever after be unable to mls_init on that DB due to a missing keypair for the given credential
85-
// this is pointlessly difficult to check right now, but we should do a uniqueness check
86-
// after WPB-20844
87-
credential
88-
.delete(&self.crypto_provider.keystore())
89-
.await
90-
.map_err(RecursiveError::mls_credential(
91-
"deleting nondistinct credential from keystore",
92-
))?;
93-
return Err(err);
94-
}
9569

9670
// only upgrade to a write guard here in order to minimize the amount of time the unique lock is held
9771
let mut guard = async_lock::RwLockUpgradableReadGuard::upgrade(guard).await;

crypto/src/mls/session/identities.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -94,39 +94,6 @@ impl Identities {
9494
self.index(signature_scheme, credential_type)?.last().cloned()
9595
}
9696

97-
/// Raise an error if the database cannot handle adding a credential with these details.
98-
pub(crate) fn ensure_distinct(
99-
&self,
100-
signature_scheme: SignatureScheme,
101-
credential_type: CredentialType,
102-
earliest_validity: u64,
103-
) -> Result<()> {
104-
let Some(credentials) = self.index(signature_scheme, credential_type) else {
105-
return Ok(());
106-
};
107-
108-
debug_assert!(
109-
credentials.is_sorted_by_key(|credential| credential.earliest_validity),
110-
"can't binary search if credentials are not sorted by validity"
111-
);
112-
debug_assert_eq!(
113-
credentials
114-
.iter()
115-
.map(|credential| credential.earliest_validity)
116-
.collect::<std::collections::HashSet<_>>()
117-
.len(),
118-
credentials.len(),
119-
"credentials must be distinct by earliest validity"
120-
);
121-
122-
match credentials.binary_search_by_key(&earliest_validity, |credential| credential.earliest_validity) {
123-
// found a matching key i.e. not distinct
124-
Ok(_) => Err(Error::CredentialConflict),
125-
// no match i.e. distinct
126-
Err(_) => Ok(()),
127-
}
128-
}
129-
13097
/// Add this credential to the identities.
13198
///
13299
/// If there already exists a credential whose signature scheme, credential type, and timestamp of creation

0 commit comments

Comments
 (0)