Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions parsec-openssl-provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ parsec-client = { git = "https://github.com/parallaxsecond/parsec-client-rust",
parsec-openssl2 = { path = "../parsec-openssl2" }
openssl-errors = "0.2.0"
env_logger = "0.10.2"
num-traits = "0.2.18"
num-derive = "0.4.2"
26 changes: 20 additions & 6 deletions parsec-openssl-provider/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ use parsec_client::BasicClient;
use std::sync::Arc;

use crate::openssl_binding::{
OSSL_ALGORITHM, OSSL_OP_KEYMGMT, OSSL_PARAM, OSSL_PARAM_INTEGER, OSSL_PARAM_UTF8_PTR,
OSSL_PROV_PARAM_BUILDINFO, OSSL_PROV_PARAM_NAME, OSSL_PROV_PARAM_STATUS,
OSSL_ALGORITHM, OSSL_OP_KEYMGMT, OSSL_OP_SIGNATURE, OSSL_PARAM, OSSL_PARAM_INTEGER,
OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_BUILDINFO, OSSL_PROV_PARAM_NAME, OSSL_PROV_PARAM_STATUS,
OSSL_PROV_PARAM_VERSION,
};

use num_derive::FromPrimitive;
use num_traits::FromPrimitive;

// Parsec provider parameters
pub const PARSEC_PROVIDER_NAME: &[u8; 24] = b"Parsec OpenSSL Provider\0";
pub const PARSEC_PROVIDER_VERSION: &[u8; 6] = b"0.1.0\0";
Expand Down Expand Up @@ -102,6 +105,13 @@ pub type ProviderQueryPtr = unsafe extern "C" fn(
// Function pointer of type OSSL_FUNC_PROVIDER_TEARDOWN
pub type ProviderTeardownPtr = unsafe extern "C" fn(provctx: *const OSSL_PROVIDER);

#[repr(i32)]
#[derive(FromPrimitive, Clone, PartialEq, Eq)]
enum ParsecProviderOperationId {
KeyMgmgt = OSSL_OP_KEYMGMT as i32,
Signature = OSSL_OP_SIGNATURE as i32,
}

// The null provider implementation currently doesn't supply any algorithms to the core
pub unsafe extern "C" fn parsec_provider_query(
_prov: *mut OSSL_PROVIDER,
Expand All @@ -110,10 +120,14 @@ pub unsafe extern "C" fn parsec_provider_query(
) -> *const OSSL_ALGORITHM {
*no_cache = 0;

match operation_id as u32 {
OSSL_OP_KEYMGMT => PARSEC_PROVIDER_KEYMGMT.as_ptr(),
OSSL_OP_SIGNATURE => PARSEC_PROVIDER_SIGNATURE.as_ptr(),
_ => std::ptr::null_mut(),
let op_id = ParsecProviderOperationId::from_i32(operation_id);
if let Some(id) = op_id {
match id {
ParsecProviderOperationId::KeyMgmgt => PARSEC_PROVIDER_KEYMGMT.as_ptr(),
ParsecProviderOperationId::Signature => PARSEC_PROVIDER_SIGNATURE.as_ptr(),
}
} else {
std::ptr::null_mut()
}
}

Expand Down