use parsec_interface::requests::ProviderID;
use serde::Deserialize;
pub mod core_provider;
#[cfg(feature = "pkcs11-provider")]
pub mod pkcs11_provider;
#[cfg(feature = "mbed-crypto-provider")]
pub mod mbed_provider;
#[cfg(feature = "tpm-provider")]
pub mod tpm_provider;
#[derive(Copy, Clone, Deserialize, Debug)]
pub enum ProviderType {
MbedProvider,
Pkcs11Provider,
TpmProvider,
}
impl ProviderType {
pub fn to_provider_id(self) -> ProviderID {
match self {
ProviderType::MbedProvider => ProviderID::MbedProvider,
ProviderType::Pkcs11Provider => ProviderID::Pkcs11Provider,
ProviderType::TpmProvider => ProviderID::TpmProvider,
}
}
}
#[derive(Deserialize, Debug)]
pub struct ProviderConfig {
pub provider_type: ProviderType,
pub key_id_manager: String,
pub library_path: Option<String>,
pub slot_number: Option<usize>,
pub user_pin: Option<String>,
pub tcti: Option<String>,
pub owner_hierarchy_auth: Option<String>,
}
use crate::authenticators::ApplicationName;
use parsec_interface::operations::{
OpAsymSign, OpAsymVerify, OpCreateKey, OpDestroyKey, OpExportPublicKey, OpImportKey,
OpListOpcodes, OpListProviders, OpPing, ProviderInfo, ResultAsymSign, ResultAsymVerify,
ResultCreateKey, ResultDestroyKey, ResultExportPublicKey, ResultImportKey, ResultListOpcodes,
ResultListProviders, ResultPing,
};
use parsec_interface::requests::{ResponseStatus, Result};
pub trait Provide {
fn describe(&self) -> ProviderInfo;
fn list_providers(&self, _op: OpListProviders) -> Result<ResultListProviders> {
Err(ResponseStatus::PsaErrorNotSupported)
}
fn list_opcodes(&self, _op: OpListOpcodes) -> Result<ResultListOpcodes>;
fn ping(&self, _op: OpPing) -> Result<ResultPing> {
Err(ResponseStatus::PsaErrorNotSupported)
}
fn create_key(&self, _app_name: ApplicationName, _op: OpCreateKey) -> Result<ResultCreateKey> {
Err(ResponseStatus::PsaErrorNotSupported)
}
fn import_key(&self, _app_name: ApplicationName, _op: OpImportKey) -> Result<ResultImportKey> {
Err(ResponseStatus::PsaErrorNotSupported)
}
fn export_public_key(
&self,
_app_name: ApplicationName,
_op: OpExportPublicKey,
) -> Result<ResultExportPublicKey> {
Err(ResponseStatus::PsaErrorNotSupported)
}
fn destroy_key(
&self,
_app_name: ApplicationName,
_op: OpDestroyKey,
) -> Result<ResultDestroyKey> {
Err(ResponseStatus::PsaErrorNotSupported)
}
fn asym_sign(&self, _app_name: ApplicationName, _op: OpAsymSign) -> Result<ResultAsymSign> {
Err(ResponseStatus::PsaErrorNotSupported)
}
fn asym_verify(
&self,
_app_name: ApplicationName,
_op: OpAsymVerify,
) -> Result<ResultAsymVerify> {
Err(ResponseStatus::PsaErrorNotSupported)
}
}