Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
beltram committed Nov 29, 2023
1 parent 4f516e8 commit 813a59f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
8 changes: 4 additions & 4 deletions crypto/src/e2e_identity/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl MlsCentral {
impl MlsConversation {
fn get_device_identities(&self, device_ids: &[ClientId]) -> CryptoResult<Vec<WireIdentity>> {
if device_ids.is_empty() {
return Err(CryptoError::ImplementationError);
return Err(CryptoError::ConsumerError);
}
self.members()
.into_iter()
Expand All @@ -97,7 +97,7 @@ impl MlsConversation {

fn get_user_identities(&self, user_ids: &[String]) -> CryptoResult<HashMap<String, Vec<WireIdentity>>> {
if user_ids.is_empty() {
return Err(CryptoError::ImplementationError);
return Err(CryptoError::ConsumerError);
}
let user_ids = user_ids.iter().map(|uid| uid.as_bytes()).collect::<Vec<_>>();
self.members()
Expand Down Expand Up @@ -191,7 +191,7 @@ pub mod tests {
);

let invalid = alice_android_central.get_device_identities(&id, &[]).await;
assert!(matches!(invalid.unwrap_err(), CryptoError::ImplementationError));
assert!(matches!(invalid.unwrap_err(), CryptoError::ConsumerError));
})
},
)
Expand Down Expand Up @@ -311,7 +311,7 @@ pub mod tests {

// Invalid usage
let invalid = alice_android_central.get_user_identities(&id, &[]).await;
assert!(matches!(invalid.unwrap_err(), CryptoError::ImplementationError));
assert!(matches!(invalid.unwrap_err(), CryptoError::ConsumerError));
})
},
)
Expand Down
3 changes: 3 additions & 0 deletions crypto/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ pub enum CryptoError {
/// We have done something terribly wrong
#[error("We have done something terribly wrong and it needs to be fixed")]
ImplementationError,
/// Tried to insert an already existing CredentialBundle
#[error("Tried to insert an already existing CredentialBundle")]
CredentialBundleConflict,
/// The consumer of this library has misused it
#[error("The consumer of this library has misused it")]
ConsumerError,
Expand Down
7 changes: 5 additions & 2 deletions crypto/src/mls/client/identities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl ClientIdentities {
Some(cbs) => {
let already_exists = !cbs.insert(cb);
if already_exists {
return Err(CryptoError::ImplementationError);
return Err(CryptoError::CredentialBundleConflict);
}
}
None => {
Expand Down Expand Up @@ -204,7 +204,10 @@ pub mod tests {
let cb = central.new_credential_bundle(&case).await;
let client = central.mls_client.as_mut().unwrap();
let push = client.identities.push_credential_bundle(case.signature_scheme(), cb);
assert!(push.is_err());
assert!(matches!(
push.unwrap_err(),
crate::CryptoError::CredentialBundleConflict
));
})
})
.await
Expand Down
9 changes: 7 additions & 2 deletions crypto/src/mls/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::{
CryptoError, CryptoResult, MlsCentral, MlsCiphersuite, MlsCredentialType, MlsError,
},
};
use core_crypto_keystore::CryptoKeystoreError;
use openmls::prelude::{Credential, CredentialType};
use openmls_basic_credential::SignatureKeyPair;
use openmls_traits::{crypto::OpenMlsCrypto, types::SignatureScheme, OpenMlsCryptoProvider};
Expand Down Expand Up @@ -360,9 +361,10 @@ impl Client {

let id = id.unwrap_or_else(|| self.id());

let credential = cb.credential.tls_serialize_detached().map_err(MlsError::from)?;
let credential = MlsCredential {
id: id.clone().into(),
credential: cb.credential.tls_serialize_detached().map_err(MlsError::from)?,
credential,
created_at: 0,
};
let created_at = credential.insert(&mut conn).await?;
Expand All @@ -373,7 +375,10 @@ impl Client {
cb.signature_key.tls_serialize_detached().map_err(MlsError::from)?,
id.clone().into(),
);
sign_kp.save(&mut conn).await?;
sign_kp.save(&mut conn).await.map_err(|e| match e {
CryptoKeystoreError::AlreadyExists => CryptoError::CredentialBundleConflict,
_ => e.into(),
})?;

// set the creation date of the signature keypair which is the same for the CredentialBundle
cb.created_at = created_at;
Expand Down

0 comments on commit 813a59f

Please sign in to comment.