-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support vendor defined mechanisms
Signed-off-by: Direktor799 <[email protected]>
- Loading branch information
1 parent
b63539d
commit 0d4698c
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2024 Contributors to the Parsec project. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
//! Mechanism types are defined with the objects and mechanism descriptions that use them. | ||
//! Vendor defined values for this type may also be specified. | ||
//! See: <https://docs.oasis-open.org/pkcs11/pkcs11-base/v3.0/os/pkcs11-base-v3.0-os.html#_Toc29976545> | ||
use std::{marker::PhantomData, ptr::null_mut}; | ||
|
||
use cryptoki_sys::CK_MECHANISM; | ||
|
||
use super::{make_mechanism, MechanismType}; | ||
|
||
/// Vendor defined mechanism. | ||
#[derive(Debug, Clone, Copy)] | ||
pub struct VendorDefinedMechanism<'a> { | ||
pub(crate) inner: CK_MECHANISM, | ||
/// Marker type to ensure we don't outlive the data | ||
_marker: PhantomData<&'a [u8]>, | ||
} | ||
|
||
impl<'a> VendorDefinedMechanism<'a> { | ||
/// Create a new vendor defined mechanism. | ||
pub fn new<T>(mechanism_type: MechanismType, params: Option<&'a T>) -> Self { | ||
Self { | ||
inner: match params { | ||
Some(params) => make_mechanism(mechanism_type.val, params), | ||
None => CK_MECHANISM { | ||
mechanism: mechanism_type.val, | ||
pParameter: null_mut(), | ||
ulParameterLen: 0, | ||
}, | ||
}, | ||
_marker: PhantomData, | ||
} | ||
} | ||
} |