From c994245326e45b8fa18f3cf759419161950cbe8b Mon Sep 17 00:00:00 2001 From: SimonThormeyer Date: Fri, 5 Jul 2024 17:00:44 +0200 Subject: [PATCH] chore: remove more async/await --- openmls/src/credentials/mod.rs | 5 ++-- openmls/src/key_packages/key_package_in.rs | 13 ++++------ openmls/src/treesync/node/validate.rs | 29 ++++++++-------------- openmls_rust_crypto/src/lib.rs | 2 +- traits/src/authentication_service.rs | 2 +- 5 files changed, 20 insertions(+), 31 deletions(-) diff --git a/openmls/src/credentials/mod.rs b/openmls/src/credentials/mod.rs index fa8c7be392..c9d4aed2c9 100644 --- a/openmls/src/credentials/mod.rs +++ b/openmls/src/credentials/mod.rs @@ -277,7 +277,7 @@ impl Credential { } } - pub async fn validate( + pub fn validate( &self, backend: &impl OpenMlsCryptoProvider, ) -> Result<(), CredentialError> { @@ -310,8 +310,7 @@ impl Credential { let credential_authentication = backend .authentication_service() - .validate_credential(credential_ref) - .await; + .validate_credential(credential_ref); if !matches!( credential_authentication, diff --git a/openmls/src/key_packages/key_package_in.rs b/openmls/src/key_packages/key_package_in.rs index b58a56b328..7b44efa2a2 100644 --- a/openmls/src/key_packages/key_package_in.rs +++ b/openmls/src/key_packages/key_package_in.rs @@ -114,7 +114,7 @@ impl KeyPackageIn { /// /// Returns a [`KeyPackage`] after having verified the signature or a /// [`KeyPackageVerifyError`] otherwise. - pub async fn validate( + pub fn validate( self, backend: &impl OpenMlsCryptoProvider, protocol_version: ProtocolVersion, @@ -122,21 +122,19 @@ impl KeyPackageIn { sender: bool, ) -> Result { self._validate(backend, protocol_version, Some(group), sender) - .await } /// Verify that this key package is valid disregarding the group it is supposed to be used with. - pub async fn standalone_validate( + pub fn standalone_validate( self, backend: &impl OpenMlsCryptoProvider, protocol_version: ProtocolVersion, sender: bool, ) -> Result { self._validate(backend, protocol_version, None, sender) - .await } - async fn _validate( + fn _validate( self, backend: &impl OpenMlsCryptoProvider, protocol_version: ProtocolVersion, @@ -159,11 +157,10 @@ impl KeyPackageIn { let leaf_node = match verifiable_leaf_node { VerifiableLeafNode::KeyPackage(leaf_node) => { if let Some(group) = group { - leaf_node.validate(group, backend, sender).await? + leaf_node.validate(group, backend, sender)? } else { leaf_node - .standalone_validate(backend, signature_scheme, sender) - .await? + .standalone_validate(backend, signature_scheme, sender)? } } _ => return Err(KeyPackageVerifyError::InvalidLeafNodeSourceType), diff --git a/openmls/src/treesync/node/validate.rs b/openmls/src/treesync/node/validate.rs index fbeaec982c..af9e7ff637 100644 --- a/openmls/src/treesync/node/validate.rs +++ b/openmls/src/treesync/node/validate.rs @@ -89,10 +89,8 @@ impl VerifiableUpdateLeafNode { } } -#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))] -#[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)] impl ValidatableLeafNode for VerifiableKeyPackageLeafNode { - async fn standalone_validate( + fn standalone_validate( self, backend: &impl OpenMlsCryptoProvider, signature_scheme: SignatureScheme, @@ -100,17 +98,16 @@ impl ValidatableLeafNode for VerifiableKeyPackageLeafNode { ) -> Result { self.validate_lifetime(sender)?; self.standalone_validate_default(backend, signature_scheme) - .await } - async fn validate( + fn validate( self, group: &PublicGroup, backend: &impl OpenMlsCryptoProvider, sender: bool, ) -> Result { self.validate_lifetime(sender)?; - self.validate_default(group, backend, sender).await + self.validate_default(group, backend, sender) } fn signature_key(&self) -> &SignaturePublicKey { @@ -148,28 +145,25 @@ impl VerifiableKeyPackageLeafNode { } } -#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))] -#[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)] pub(crate) trait ValidatableLeafNode: Verifiable + Send + Sync + Sized where LeafNode: VerifiedStruct, { - async fn standalone_validate( + fn standalone_validate( self, backend: &impl OpenMlsCryptoProvider, signature_scheme: SignatureScheme, _sender: bool, ) -> Result { self.standalone_validate_default(backend, signature_scheme) - .await } - async fn standalone_validate_default( + fn standalone_validate_default( self, backend: &impl OpenMlsCryptoProvider, signature_scheme: SignatureScheme, ) -> Result { - self.validate_credential(backend).await?; + self.validate_credential(backend)?; let extension_types = self.extension_types(); let leaf_node = self.verify_signature(backend.crypto(), signature_scheme)?; @@ -179,16 +173,16 @@ where } /// Validate a LeafNode as per https://www.rfc-editor.org/rfc/rfc9420.html#name-leaf-node-validation - async fn validate( + fn validate( self, group: &PublicGroup, backend: &impl OpenMlsCryptoProvider, sender: bool, ) -> Result { - self.validate_default(group, backend, sender).await + self.validate_default(group, backend, sender) } - async fn validate_default( + fn validate_default( self, group: &PublicGroup, backend: &impl OpenMlsCryptoProvider, @@ -200,7 +194,6 @@ where self.validate_signature_encryption_key_unique(tree)?; let signature_scheme = group.ciphersuite().signature_algorithm(); self.standalone_validate(backend, signature_scheme, sender) - .await } fn signature_key(&self) -> &SignaturePublicKey; @@ -246,11 +239,11 @@ where Ok(()) } - async fn validate_credential( + fn validate_credential( &self, backend: &impl OpenMlsCryptoProvider, ) -> Result<(), LeafNodeValidationError> { - Ok(self.credential().validate(backend).await?) + Ok(self.credential().validate(backend)?) } /// Verify that the following fields are unique among the members of the group: signature_key diff --git a/openmls_rust_crypto/src/lib.rs b/openmls_rust_crypto/src/lib.rs index e60a816b2c..f58c99436c 100644 --- a/openmls_rust_crypto/src/lib.rs +++ b/openmls_rust_crypto/src/lib.rs @@ -17,7 +17,7 @@ pub struct DummyAuthenticationService; impl openmls_traits::authentication_service::AuthenticationServiceDelegate for DummyAuthenticationService { - async fn validate_credential<'a>( + fn validate_credential<'a>( &'a self, _credential: openmls_traits::authentication_service::CredentialRef<'a>, ) -> openmls_traits::authentication_service::CredentialAuthenticationStatus { diff --git a/traits/src/authentication_service.rs b/traits/src/authentication_service.rs index a4773998d4..7dbbc6ef0b 100644 --- a/traits/src/authentication_service.rs +++ b/traits/src/authentication_service.rs @@ -33,7 +33,7 @@ impl std::fmt::Display for CredentialAuthenticationStatus { #[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))] #[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)] pub trait AuthenticationServiceDelegate: std::fmt::Debug + Send + Sync { - async fn validate_credential<'a>( + fn validate_credential<'a>( &'a self, credential: CredentialRef<'a>, ) -> CredentialAuthenticationStatus;