From a52f51ca97a526e7cc49f5521739222aa22d8b6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gonz=C3=A1lez?= Date: Wed, 14 Feb 2024 14:24:33 +0000 Subject: [PATCH] Add Parsec Basic Client MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomás González --- parsec-openssl-provider/Cargo.toml | 4 +++- parsec-openssl-provider/src/lib.rs | 20 +++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/parsec-openssl-provider/Cargo.toml b/parsec-openssl-provider/Cargo.toml index 2a412583..07137e72 100644 --- a/parsec-openssl-provider/Cargo.toml +++ b/parsec-openssl-provider/Cargo.toml @@ -10,6 +10,8 @@ categories = ["cryptography", "hardware-support"] edition = "2021" [dependencies] +lazy_static = "1.4.0" +log = "0.4" +parsec-client = { git = "https://github.com/parallaxsecond/parsec-client-rust", tag="0.16.0" } parsec-openssl2 = { path = "../parsec-openssl2" } openssl-errors = "0.2.0" -log = "0.4" diff --git a/parsec-openssl-provider/src/lib.rs b/parsec-openssl-provider/src/lib.rs index 22c0bb96..8c35eaa6 100644 --- a/parsec-openssl-provider/src/lib.rs +++ b/parsec-openssl-provider/src/lib.rs @@ -1,9 +1,10 @@ // Copyright 2023 Contributors to the Parsec project. // SPDX-License-Identifier: Apache-2.0 use std::mem; +use std::sync::Mutex; -pub use parsec_openssl2::*; pub use openssl_errors::*; +pub use parsec_openssl2::*; mod provider; use provider::*; @@ -11,9 +12,17 @@ use provider::*; mod catch; use catch::r#catch; -// The init function populates the dispatch table and returns a NULL pointer -// to the provider context. This needs to be changed when key management and -// crypto support is added to the provider. +use parsec_client::error::Result as ClientResult; +use parsec_client::BasicClient; + +const PROJECT_NAME: &str = env!("CARGO_PKG_NAME"); + +lazy_static::lazy_static! { + static ref PARSEC_PROVIDER_CTX: Mutex> = Mutex::new(BasicClient::new(Some(PROJECT_NAME.to_string()))); +} + +// The init function populates the dispatch table and returns a void pointer +// to the provider context (which contains the parsec basic client). pub unsafe fn parsec_provider_provider_init( _handle: *const OSSL_CORE_HANDLE, _in_: *const OSSL_DISPATCH, @@ -49,7 +58,8 @@ pub unsafe fn parsec_provider_provider_init( }); *out = DISPATCH_TABLE.as_ptr(); - *provctx = std::ptr::null_mut(); + let ptr: *const Mutex> = &*PARSEC_PROVIDER_CTX; + *provctx = ptr as VOID_PTR; Ok(()) }