Skip to content

Commit 13f40fa

Browse files
Improved safety comment on make_mechanism()
Signed-off-by: Jacob Prud'homme <[email protected]>
1 parent 074c21b commit 13f40fa

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

cryptoki/src/mechanism/mod.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -1252,11 +1252,17 @@ impl From<&Mechanism<'_>> for CK_MECHANISM {
12521252
fn make_mechanism<T>(mechanism: CK_MECHANISM_TYPE, param: &T) -> CK_MECHANISM {
12531253
CK_MECHANISM {
12541254
mechanism,
1255-
// SAFETY: Parameters that expect to have some part of themselves
1256-
// mutated (such as additional_derived_keys in Kbkdf{*}Params) should
1257-
// indicate this to the end user by marking the relevant constructor
1258-
// parameters as mut. Otherwise, we should generally not expect the
1259-
// backend to mutate the parameters, so this cast is fine.
1255+
/* SAFETY: Parameters that expect to have some part of themselves
1256+
* mutated should indicate this to the end user by marking both the
1257+
* relevant constructor parameters and the type's PhantomData as mut.
1258+
* Otherwise, we should generally not expect the backend to mutate the
1259+
* parameters, so this cast is fine.
1260+
* The list of such mutable parameter types so far:
1261+
* - aead::GcmParams
1262+
* - aead::GcmMessageParams
1263+
* - kbkdf::KbkdfParams
1264+
* - kbkdf::KbkdfFeedbackParams
1265+
**/
12601266
pParameter: param as *const T as *mut c_void,
12611267
ulParameterLen: size_of::<T>()
12621268
.try_into()

0 commit comments

Comments
 (0)