Skip to content

Commit add6291

Browse files
committed
feat: pass value to vendor mechs
Signed-off-by: Direktor799 <[email protected]>
1 parent 12e21fa commit add6291

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

cryptoki/src/mechanism/mod.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -304,23 +304,24 @@ impl MechanismType {
304304
///
305305
/// # Arguments
306306
///
307-
/// * `adding` - The adding based on `CKM_VENDOR_DEFINED`
307+
/// * `val` - The value of vendor defined mechanism
308308
///
309-
/// Usually vendors defines custom mechanism like this:
310-
/// ```c
311-
/// #define CKM_SOME_CUSTOM_MECH (CKM_VENDOR_DEFINED | 0x00000001UL)
312-
/// ```
309+
/// # Errors
310+
///
311+
/// If `val` is less then `CKM_VENDOR_DEFINED`, a `Error::InvalidValue` will be returned
313312
///
314-
/// It maps to
313+
/// # Examples
315314
/// ```rust
316-
/// use cryptoki::mechanism::MechanismType;
315+
/// use cryptoki::mechanism::{vendor_defined::CKM_VENDOR_DEFINED, MechanismType};
317316
///
318-
/// pub const CKM_SOME_CUSTOM_MECH: MechanismType =
319-
/// MechanismType::new_vendor_defined(0x00000001);
317+
/// let some_custom_mech: MechanismType =
318+
/// MechanismType::new_vendor_defined(CKM_VENDOR_DEFINED | 0x00000001).unwrap();
320319
/// ```
321-
pub const fn new_vendor_defined(adding: CK_ULONG) -> MechanismType {
322-
MechanismType {
323-
val: CKM_VENDOR_DEFINED | adding,
320+
pub fn new_vendor_defined(val: CK_MECHANISM_TYPE) -> crate::error::Result<MechanismType> {
321+
if val < CKM_VENDOR_DEFINED {
322+
Err(Error::InvalidValue)
323+
} else {
324+
Ok(MechanismType { val })
324325
}
325326
}
326327

cryptoki/src/mechanism/vendor_defined.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
use std::{marker::PhantomData, ptr::null_mut};
88

9+
pub use cryptoki_sys::CKM_VENDOR_DEFINED;
910
use cryptoki_sys::CK_MECHANISM;
1011

1112
use super::{make_mechanism, MechanismType};

0 commit comments

Comments
 (0)