From 37cf90762835e74fb4cdf8dfe48d558faa27792e Mon Sep 17 00:00:00 2001 From: Sam Davis Date: Fri, 10 Sep 2021 16:39:02 +0100 Subject: [PATCH] Added CanDoCrypto to basic client. Added the CanDoCrypto operation to the basic client by adding the can_do_crypto function to the implementation of BasicClient Signed-off-by: Sam Davis --- Cargo.toml | 2 +- src/core/basic_client.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index f33844f..f03f704 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ edition = "2018" documentation = "https://docs.rs/crate/parsec-client" [dependencies] -parsec-interface = "0.25.0" +parsec-interface = { git = "https://github.com/Kakemone/parsec-interface-rs", branch = "CanDoCrypto_patch" } num = "0.3.0" log = "0.4.11" derivative = "2.1.1" diff --git a/src/core/basic_client.rs b/src/core/basic_client.rs index 19b7382..ddc281c 100644 --- a/src/core/basic_client.rs +++ b/src/core/basic_client.rs @@ -5,6 +5,7 @@ use super::operation_client::OperationClient; use crate::auth::Authentication; use crate::error::{ClientErrorKind, Error, Result}; use log::{debug, warn}; +use parsec_interface::operations::can_do_crypto::{CheckType, Operation as CanDoCrypto}; use parsec_interface::operations::delete_client::Operation as DeleteClient; use parsec_interface::operations::list_authenticators::{ AuthenticatorInfo, Operation as ListAuthenticators, @@ -1284,6 +1285,31 @@ impl BasicClient { } } + /// **[Capability Discovery Operation]** Check if attributes are supported. + /// + /// Checks if the given attributes are supported for the given type of operation. + /// + /// #Errors + /// + /// This operation never return a result but will terminate with Err(Success) or + /// Err(PsaErrorNotSupported) indicating whether the attributes are supported. + /// + /// See the operation-specific response codes returned by the service + /// [here](https://parallaxsecond.github.io/parsec-book/parsec_client/operations/can_do_crypto.html#specific-response-status-codes). + pub fn can_do_crypto(&self, check_type: CheckType, attributes: Attributes) -> Result<()> { + let crypto_provider = self.can_provide_crypto()?; + let op = CanDoCrypto { + check_type, + attributes, + }; + let _ = self.op_client.process_operation( + NativeOperation::CanDoCrypto(op), + crypto_provider, + &self.auth_data, + )?; + Ok(()) + } + fn can_provide_crypto(&self) -> Result { match self.implicit_provider { ProviderId::Core => Err(Error::Client(ClientErrorKind::InvalidProvider)),