diff --git a/Cargo.lock b/Cargo.lock index 960ee8e01308..473b05cba55d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3848,9 +3848,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkcs11" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c20593a99fe08068cbe2b59001527f36021d6ad53ac5f2d8793fcf2fe94015a0" +checksum = "45712272d3a9d9a26471f6bee1596574d38df0136dd7eb163ed736913dc1f6bf" dependencies = [ "libloading 0.5.2", "num-bigint", diff --git a/third_party/rust/pkcs11/.cargo-checksum.json b/third_party/rust/pkcs11/.cargo-checksum.json index 8f86e37c0d65..e1313dc3eee8 100644 --- a/third_party/rust/pkcs11/.cargo-checksum.json +++ b/third_party/rust/pkcs11/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"b04ba4906f065e937aac92197aaa7ec3628f52c0c6277cc27401d571a3d4472c","LICENSE":"cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30","NOTICE":"6e0c856925602c18a04e173be3a6e2d812a7ca4501176642a07fec1af97e0eab","README.md":"4f227c9d8a3c07e4b82b2812d3fcc512cdf477a4daf2c9c955f49fb2e94cbab8","rustfmt.toml":"925e9c7b3d6df043a11531da116439cc0d0b0368b682875a8fb0e8229fc7df01","src/errors.rs":"efcc4e8472ee06de82b122017cca4e87898034c98bc9b593110b2a4f8a557e26","src/functions.rs":"1bec1b1ac5c38d3db527880ab5b06005f567a52bba7b98b1ec0fdf64f7d0a68b","src/lib.rs":"3d22aaedf17669d9ca5f50c7ff892e7d874d257369fa40b49ed582409ee94455","src/tests.rs":"b7257ef2bff4321ac03095af9b4015fc9a88d2cddddb94ca8ae8f7516b19e7f1","src/types.rs":"797b99955b4fa30ad373ee435076c6d251978bb6ae724cc9a082020fb8f984fc"},"package":"c20593a99fe08068cbe2b59001527f36021d6ad53ac5f2d8793fcf2fe94015a0"} \ No newline at end of file +{"files":{"Cargo.toml":"59618cbbc693fe0ca7da46fc4620beb3a3e6342b16f7963319e4581b4325b8c9","LICENSE":"cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30","NOTICE":"6e0c856925602c18a04e173be3a6e2d812a7ca4501176642a07fec1af97e0eab","README.md":"3acf1fb95028c85929c921b4bcda21f7ed7a4fefceecf93ddbb24eed6f5cb690","rustfmt.toml":"925e9c7b3d6df043a11531da116439cc0d0b0368b682875a8fb0e8229fc7df01","src/errors.rs":"745606ea0fd8b428585591fd2eb924814a28a8f957f93f5ca9d98127d420bf30","src/functions.rs":"1bec1b1ac5c38d3db527880ab5b06005f567a52bba7b98b1ec0fdf64f7d0a68b","src/lib.rs":"436684e76363670a38baf54872b455a694b45f6ebf9118cf4c82f6de83eadce0","src/tests.rs":"0b31ebcd2e5a1e5b87272e396d1a40cc557a41af67adee2dda789dbb96529260","src/types.rs":"bb7af6dd052d90499ac83f2b56359ca36db23d87cbe59a5a248fc0b2237b49c6"},"package":"45712272d3a9d9a26471f6bee1596574d38df0136dd7eb163ed736913dc1f6bf"} \ No newline at end of file diff --git a/third_party/rust/pkcs11/Cargo.toml b/third_party/rust/pkcs11/Cargo.toml index 7dbaf2819914..fe2ba55bf775 100644 --- a/third_party/rust/pkcs11/Cargo.toml +++ b/third_party/rust/pkcs11/Cargo.toml @@ -12,7 +12,7 @@ [package] name = "pkcs11" -version = "0.4.1" +version = "0.4.2" authors = ["Marcus Heese "] exclude = ["pkcs11-docs/**"] description = "Rust PKCS#11 Library" diff --git a/third_party/rust/pkcs11/README.md b/third_party/rust/pkcs11/README.md index 09f552e3aaa8..319ce248f22d 100644 --- a/third_party/rust/pkcs11/README.md +++ b/third_party/rust/pkcs11/README.md @@ -13,8 +13,11 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> + # Rust PKCS#11 Library +[![Build Status](https://travis-ci.org/mheese/rust-pkcs11.svg?branch=master)](https://travis-ci.org/mheese/rust-pkcs11) + This is a library which brings support for PKCS#11 to Rust. It is aiming at having both a very low-level API to map the PKCS#11 functionality to Rust as well as having a higher-level API for more easy usage as well as bringing more safety for programming against PKCS#11. ## Testing @@ -24,6 +27,7 @@ Testing is currently done with [SoftHSM2](https://github.com/opendnssec/SoftHSMv ### Status Here is a list of the implementation status and plans on what to do next: + - [x] Dynamic loading of PKCS#11 module (thanks to [libloading](https://github.com/nagisa/rust_libloading "libloading Repo")) - [x] Initializing and Dropping PKCS#11 context - [x] Implementing Token and PIN Management functions diff --git a/third_party/rust/pkcs11/src/errors.rs b/third_party/rust/pkcs11/src/errors.rs index fbb45d220d0a..87d35d39dd31 100644 --- a/third_party/rust/pkcs11/src/errors.rs +++ b/third_party/rust/pkcs11/src/errors.rs @@ -41,7 +41,7 @@ impl std::fmt::Display for Error { } impl std::error::Error for Error { - fn cause(&self) -> Option<&std::error::Error> { + fn cause(&self) -> Option<&dyn std::error::Error> { if let Error::Io(ref err) = self { Some(err) } else { diff --git a/third_party/rust/pkcs11/src/lib.rs b/third_party/rust/pkcs11/src/lib.rs index 1c71ff038583..f5c1e9f9761f 100644 --- a/third_party/rust/pkcs11/src/lib.rs +++ b/third_party/rust/pkcs11/src/lib.rs @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#![allow(non_camel_case_types, non_snake_case)] +#![allow(non_camel_case_types, non_snake_case, clippy::unreadable_literal)] extern crate libloading; extern crate num_bigint; @@ -47,9 +47,10 @@ trait CkFrom { impl CkFrom for CK_BBOOL { fn from(b: bool) -> Self { - match b { - true => 1, - false => 0, + if b { + 1 + } else { + 0 } } } @@ -72,7 +73,7 @@ fn label_from_str(label: &str) -> [CK_UTF8CHAR; 32] { let mut buf = [0; 4]; let bytes = c.encode_utf8(&mut buf).as_bytes(); for b in bytes { - lab[i] = b.clone(); + lab[i] = *b; i += 1; } } else { @@ -165,88 +166,90 @@ impl Ctx { { unsafe { let lib = libloading::Library::new(filename.as_ref())?; - let mut list: CK_FUNCTION_LIST_PTR = mem::uninitialized(); + let mut list = mem::MaybeUninit::uninit(); { let func: libloading::Symbol CK_RV> = lib.get(b"C_GetFunctionList")?; - match func(&mut list) { + match func(list.as_mut_ptr()) { CKR_OK => (), err => return Err(Error::Pkcs11(err)), } } + let list_ptr = *list.as_ptr(); + Ok(Ctx { - lib: lib, + lib, _is_initialized: false, - version: (*list).version.clone(), - C_Initialize: (*list).C_Initialize.ok_or(Error::Module("C_Initialize function not found"))?, - C_Finalize: (*list).C_Finalize.ok_or(Error::Module("C_Finalize function not found"))?, - C_GetInfo: (*list).C_GetInfo.ok_or(Error::Module("C_GetInfo function not found"))?, - C_GetFunctionList: (*list).C_GetFunctionList.ok_or(Error::Module("C_GetFunctionList function not found"))?, - C_GetSlotList: (*list).C_GetSlotList.ok_or(Error::Module("C_GetSlotList function not found"))?, - C_GetSlotInfo: (*list).C_GetSlotInfo.ok_or(Error::Module("C_GetSlotInfo function not found"))?, - C_GetTokenInfo: (*list).C_GetTokenInfo.ok_or(Error::Module("C_GetTokenInfo function not found"))?, - C_GetMechanismList: (*list).C_GetMechanismList.ok_or(Error::Module("C_GetMechanismList function not found"))?, - C_GetMechanismInfo: (*list).C_GetMechanismInfo.ok_or(Error::Module("C_GetMechanismInfo function not found"))?, - C_InitToken: (*list).C_InitToken.ok_or(Error::Module("C_InitToken function not found"))?, - C_InitPIN: (*list).C_InitPIN.ok_or(Error::Module("C_InitPIN function not found"))?, - C_SetPIN: (*list).C_SetPIN.ok_or(Error::Module("C_SetPIN function not found"))?, - C_OpenSession: (*list).C_OpenSession.ok_or(Error::Module("C_OpenSession function not found"))?, - C_CloseSession: (*list).C_CloseSession.ok_or(Error::Module("C_CloseSession function not found"))?, - C_CloseAllSessions: (*list).C_CloseAllSessions.ok_or(Error::Module("C_CloseAllSessions function not found"))?, - C_GetSessionInfo: (*list).C_GetSessionInfo.ok_or(Error::Module("C_GetSessionInfo function not found"))?, - C_GetOperationState: (*list).C_GetOperationState.ok_or(Error::Module("C_GetOperationState function not found"))?, - C_SetOperationState: (*list).C_SetOperationState.ok_or(Error::Module("C_SetOperationState function not found"))?, - C_Login: (*list).C_Login.ok_or(Error::Module("C_Login function not found"))?, - C_Logout: (*list).C_Logout.ok_or(Error::Module("C_Logout function not found"))?, - C_CreateObject: (*list).C_CreateObject.ok_or(Error::Module("C_CreateObject function not found"))?, - C_CopyObject: (*list).C_CopyObject.ok_or(Error::Module("C_CopyObject function not found"))?, - C_DestroyObject: (*list).C_DestroyObject.ok_or(Error::Module("C_DestroyObject function not found"))?, - C_GetObjectSize: (*list).C_GetObjectSize.ok_or(Error::Module("C_GetObjectSize function not found"))?, - C_GetAttributeValue: (*list).C_GetAttributeValue.ok_or(Error::Module("C_GetAttributeValue function not found"))?, - C_SetAttributeValue: (*list).C_SetAttributeValue.ok_or(Error::Module("C_SetAttributeValue function not found"))?, - C_FindObjectsInit: (*list).C_FindObjectsInit.ok_or(Error::Module("C_FindObjectsInit function not found"))?, - C_FindObjects: (*list).C_FindObjects.ok_or(Error::Module("C_FindObjects function not found"))?, - C_FindObjectsFinal: (*list).C_FindObjectsFinal.ok_or(Error::Module("C_FindObjectsFinal function not found"))?, - C_EncryptInit: (*list).C_EncryptInit.ok_or(Error::Module("C_EncryptInit function not found"))?, - C_Encrypt: (*list).C_Encrypt.ok_or(Error::Module("C_Encrypt function not found"))?, - C_EncryptUpdate: (*list).C_EncryptUpdate.ok_or(Error::Module("C_EncryptUpdate function not found"))?, - C_EncryptFinal: (*list).C_EncryptFinal.ok_or(Error::Module("C_EncryptFinal function not found"))?, - C_DecryptInit: (*list).C_DecryptInit.ok_or(Error::Module("C_DecryptInit function not found"))?, - C_Decrypt: (*list).C_Decrypt.ok_or(Error::Module("C_Decrypt function not found"))?, - C_DecryptUpdate: (*list).C_DecryptUpdate.ok_or(Error::Module("C_DecryptUpdate function not found"))?, - C_DecryptFinal: (*list).C_DecryptFinal.ok_or(Error::Module("C_DecryptFinal function not found"))?, - C_DigestInit: (*list).C_DigestInit.ok_or(Error::Module("C_DigestInit function not found"))?, - C_Digest: (*list).C_Digest.ok_or(Error::Module("C_Digest function not found"))?, - C_DigestUpdate: (*list).C_DigestUpdate.ok_or(Error::Module("C_DigestUpdate function not found"))?, - C_DigestKey: (*list).C_DigestKey.ok_or(Error::Module("C_DigestKey function not found"))?, - C_DigestFinal: (*list).C_DigestFinal.ok_or(Error::Module("C_DigestFinal function not found"))?, - C_SignInit: (*list).C_SignInit.ok_or(Error::Module("C_SignInit function not found"))?, - C_Sign: (*list).C_Sign.ok_or(Error::Module("C_Sign function not found"))?, - C_SignUpdate: (*list).C_SignUpdate.ok_or(Error::Module("C_SignUpdate function not found"))?, - C_SignFinal: (*list).C_SignFinal.ok_or(Error::Module("C_SignFinal function not found"))?, - C_SignRecoverInit: (*list).C_SignRecoverInit.ok_or(Error::Module("C_SignRecoverInit function not found"))?, - C_SignRecover: (*list).C_SignRecover.ok_or(Error::Module("C_SignRecover function not found"))?, - C_VerifyInit: (*list).C_VerifyInit.ok_or(Error::Module("C_VerifyInit function not found"))?, - C_Verify: (*list).C_Verify.ok_or(Error::Module("C_Verify function not found"))?, - C_VerifyUpdate: (*list).C_VerifyUpdate.ok_or(Error::Module("C_VerifyUpdate function not found"))?, - C_VerifyFinal: (*list).C_VerifyFinal.ok_or(Error::Module("C_VerifyFinal function not found"))?, - C_VerifyRecoverInit: (*list).C_VerifyRecoverInit.ok_or(Error::Module("C_VerifyRecoverInit function not found"))?, - C_VerifyRecover: (*list).C_VerifyRecover.ok_or(Error::Module("C_VerifyRecover function not found"))?, - C_DigestEncryptUpdate: (*list).C_DigestEncryptUpdate.ok_or(Error::Module("C_DigestEncryptUpdate function not found"))?, - C_DecryptDigestUpdate: (*list).C_DecryptDigestUpdate.ok_or(Error::Module("C_DecryptDigestUpdate function not found"))?, - C_SignEncryptUpdate: (*list).C_SignEncryptUpdate.ok_or(Error::Module("C_SignEncryptUpdate function not found"))?, - C_DecryptVerifyUpdate: (*list).C_DecryptVerifyUpdate.ok_or(Error::Module("C_DecryptVerifyUpdate function not found"))?, - C_GenerateKey: (*list).C_GenerateKey.ok_or(Error::Module("C_GenerateKey function not found"))?, - C_GenerateKeyPair: (*list).C_GenerateKeyPair.ok_or(Error::Module("C_GenerateKeyPair function not found"))?, - C_WrapKey: (*list).C_WrapKey.ok_or(Error::Module("C_WrapKey function not found"))?, - C_UnwrapKey: (*list).C_UnwrapKey.ok_or(Error::Module("C_UnwrapKey function not found"))?, - C_DeriveKey: (*list).C_DeriveKey.ok_or(Error::Module("C_DeriveKey function not found"))?, - C_SeedRandom: (*list).C_SeedRandom.ok_or(Error::Module("C_SeedRandom function not found"))?, - C_GenerateRandom: (*list).C_GenerateRandom.ok_or(Error::Module("C_GenerateRandom function not found"))?, - C_GetFunctionStatus: (*list).C_GetFunctionStatus.ok_or(Error::Module("C_GetFunctionStatus function not found"))?, - C_CancelFunction: (*list).C_CancelFunction.ok_or(Error::Module("C_CancelFunction function not found"))?, + version: (*list_ptr).version, + C_Initialize: (*list_ptr).C_Initialize.ok_or(Error::Module("C_Initialize function not found"))?, + C_Finalize: (*list_ptr).C_Finalize.ok_or(Error::Module("C_Finalize function not found"))?, + C_GetInfo: (*list_ptr).C_GetInfo.ok_or(Error::Module("C_GetInfo function not found"))?, + C_GetFunctionList: (*list_ptr).C_GetFunctionList.ok_or(Error::Module("C_GetFunctionList function not found"))?, + C_GetSlotList: (*list_ptr).C_GetSlotList.ok_or(Error::Module("C_GetSlotList function not found"))?, + C_GetSlotInfo: (*list_ptr).C_GetSlotInfo.ok_or(Error::Module("C_GetSlotInfo function not found"))?, + C_GetTokenInfo: (*list_ptr).C_GetTokenInfo.ok_or(Error::Module("C_GetTokenInfo function not found"))?, + C_GetMechanismList: (*list_ptr).C_GetMechanismList.ok_or(Error::Module("C_GetMechanismList function not found"))?, + C_GetMechanismInfo: (*list_ptr).C_GetMechanismInfo.ok_or(Error::Module("C_GetMechanismInfo function not found"))?, + C_InitToken: (*list_ptr).C_InitToken.ok_or(Error::Module("C_InitToken function not found"))?, + C_InitPIN: (*list_ptr).C_InitPIN.ok_or(Error::Module("C_InitPIN function not found"))?, + C_SetPIN: (*list_ptr).C_SetPIN.ok_or(Error::Module("C_SetPIN function not found"))?, + C_OpenSession: (*list_ptr).C_OpenSession.ok_or(Error::Module("C_OpenSession function not found"))?, + C_CloseSession: (*list_ptr).C_CloseSession.ok_or(Error::Module("C_CloseSession function not found"))?, + C_CloseAllSessions: (*list_ptr).C_CloseAllSessions.ok_or(Error::Module("C_CloseAllSessions function not found"))?, + C_GetSessionInfo: (*list_ptr).C_GetSessionInfo.ok_or(Error::Module("C_GetSessionInfo function not found"))?, + C_GetOperationState: (*list_ptr).C_GetOperationState.ok_or(Error::Module("C_GetOperationState function not found"))?, + C_SetOperationState: (*list_ptr).C_SetOperationState.ok_or(Error::Module("C_SetOperationState function not found"))?, + C_Login: (*list_ptr).C_Login.ok_or(Error::Module("C_Login function not found"))?, + C_Logout: (*list_ptr).C_Logout.ok_or(Error::Module("C_Logout function not found"))?, + C_CreateObject: (*list_ptr).C_CreateObject.ok_or(Error::Module("C_CreateObject function not found"))?, + C_CopyObject: (*list_ptr).C_CopyObject.ok_or(Error::Module("C_CopyObject function not found"))?, + C_DestroyObject: (*list_ptr).C_DestroyObject.ok_or(Error::Module("C_DestroyObject function not found"))?, + C_GetObjectSize: (*list_ptr).C_GetObjectSize.ok_or(Error::Module("C_GetObjectSize function not found"))?, + C_GetAttributeValue: (*list_ptr).C_GetAttributeValue.ok_or(Error::Module("C_GetAttributeValue function not found"))?, + C_SetAttributeValue: (*list_ptr).C_SetAttributeValue.ok_or(Error::Module("C_SetAttributeValue function not found"))?, + C_FindObjectsInit: (*list_ptr).C_FindObjectsInit.ok_or(Error::Module("C_FindObjectsInit function not found"))?, + C_FindObjects: (*list_ptr).C_FindObjects.ok_or(Error::Module("C_FindObjects function not found"))?, + C_FindObjectsFinal: (*list_ptr).C_FindObjectsFinal.ok_or(Error::Module("C_FindObjectsFinal function not found"))?, + C_EncryptInit: (*list_ptr).C_EncryptInit.ok_or(Error::Module("C_EncryptInit function not found"))?, + C_Encrypt: (*list_ptr).C_Encrypt.ok_or(Error::Module("C_Encrypt function not found"))?, + C_EncryptUpdate: (*list_ptr).C_EncryptUpdate.ok_or(Error::Module("C_EncryptUpdate function not found"))?, + C_EncryptFinal: (*list_ptr).C_EncryptFinal.ok_or(Error::Module("C_EncryptFinal function not found"))?, + C_DecryptInit: (*list_ptr).C_DecryptInit.ok_or(Error::Module("C_DecryptInit function not found"))?, + C_Decrypt: (*list_ptr).C_Decrypt.ok_or(Error::Module("C_Decrypt function not found"))?, + C_DecryptUpdate: (*list_ptr).C_DecryptUpdate.ok_or(Error::Module("C_DecryptUpdate function not found"))?, + C_DecryptFinal: (*list_ptr).C_DecryptFinal.ok_or(Error::Module("C_DecryptFinal function not found"))?, + C_DigestInit: (*list_ptr).C_DigestInit.ok_or(Error::Module("C_DigestInit function not found"))?, + C_Digest: (*list_ptr).C_Digest.ok_or(Error::Module("C_Digest function not found"))?, + C_DigestUpdate: (*list_ptr).C_DigestUpdate.ok_or(Error::Module("C_DigestUpdate function not found"))?, + C_DigestKey: (*list_ptr).C_DigestKey.ok_or(Error::Module("C_DigestKey function not found"))?, + C_DigestFinal: (*list_ptr).C_DigestFinal.ok_or(Error::Module("C_DigestFinal function not found"))?, + C_SignInit: (*list_ptr).C_SignInit.ok_or(Error::Module("C_SignInit function not found"))?, + C_Sign: (*list_ptr).C_Sign.ok_or(Error::Module("C_Sign function not found"))?, + C_SignUpdate: (*list_ptr).C_SignUpdate.ok_or(Error::Module("C_SignUpdate function not found"))?, + C_SignFinal: (*list_ptr).C_SignFinal.ok_or(Error::Module("C_SignFinal function not found"))?, + C_SignRecoverInit: (*list_ptr).C_SignRecoverInit.ok_or(Error::Module("C_SignRecoverInit function not found"))?, + C_SignRecover: (*list_ptr).C_SignRecover.ok_or(Error::Module("C_SignRecover function not found"))?, + C_VerifyInit: (*list_ptr).C_VerifyInit.ok_or(Error::Module("C_VerifyInit function not found"))?, + C_Verify: (*list_ptr).C_Verify.ok_or(Error::Module("C_Verify function not found"))?, + C_VerifyUpdate: (*list_ptr).C_VerifyUpdate.ok_or(Error::Module("C_VerifyUpdate function not found"))?, + C_VerifyFinal: (*list_ptr).C_VerifyFinal.ok_or(Error::Module("C_VerifyFinal function not found"))?, + C_VerifyRecoverInit: (*list_ptr).C_VerifyRecoverInit.ok_or(Error::Module("C_VerifyRecoverInit function not found"))?, + C_VerifyRecover: (*list_ptr).C_VerifyRecover.ok_or(Error::Module("C_VerifyRecover function not found"))?, + C_DigestEncryptUpdate: (*list_ptr).C_DigestEncryptUpdate.ok_or(Error::Module("C_DigestEncryptUpdate function not found"))?, + C_DecryptDigestUpdate: (*list_ptr).C_DecryptDigestUpdate.ok_or(Error::Module("C_DecryptDigestUpdate function not found"))?, + C_SignEncryptUpdate: (*list_ptr).C_SignEncryptUpdate.ok_or(Error::Module("C_SignEncryptUpdate function not found"))?, + C_DecryptVerifyUpdate: (*list_ptr).C_DecryptVerifyUpdate.ok_or(Error::Module("C_DecryptVerifyUpdate function not found"))?, + C_GenerateKey: (*list_ptr).C_GenerateKey.ok_or(Error::Module("C_GenerateKey function not found"))?, + C_GenerateKeyPair: (*list_ptr).C_GenerateKeyPair.ok_or(Error::Module("C_GenerateKeyPair function not found"))?, + C_WrapKey: (*list_ptr).C_WrapKey.ok_or(Error::Module("C_WrapKey function not found"))?, + C_UnwrapKey: (*list_ptr).C_UnwrapKey.ok_or(Error::Module("C_UnwrapKey function not found"))?, + C_DeriveKey: (*list_ptr).C_DeriveKey.ok_or(Error::Module("C_DeriveKey function not found"))?, + C_SeedRandom: (*list_ptr).C_SeedRandom.ok_or(Error::Module("C_SeedRandom function not found"))?, + C_GenerateRandom: (*list_ptr).C_GenerateRandom.ok_or(Error::Module("C_GenerateRandom function not found"))?, + C_GetFunctionStatus: (*list_ptr).C_GetFunctionStatus.ok_or(Error::Module("C_GetFunctionStatus function not found"))?, + C_CancelFunction: (*list_ptr).C_CancelFunction.ok_or(Error::Module("C_CancelFunction function not found"))?, // Functions added in for Cryptoki Version 2.01 or later - C_WaitForSlotEvent: (*list).C_WaitForSlotEvent, + C_WaitForSlotEvent: (*list_ptr).C_WaitForSlotEvent, }) } } @@ -317,9 +320,9 @@ impl Ctx { } pub fn get_function_list(&self) -> Result { - let mut list: CK_FUNCTION_LIST_PTR = unsafe { mem::uninitialized() }; - match (self.C_GetFunctionList)(&mut list) { - CKR_OK => unsafe { Ok((*list).clone()) }, + let mut list = mem::MaybeUninit::uninit(); + match (self.C_GetFunctionList)(&mut list.as_mut_ptr()) { + CKR_OK => unsafe { Ok(*list.as_ptr()) }, err => Err(Error::Pkcs11(err)), } } @@ -532,7 +535,7 @@ impl Ctx { authentication_key: Option, ) -> Result<(), Error> { self.initialized()?; - let mut operation_state = operation_state.clone(); + let mut operation_state = operation_state; match (self.C_SetOperationState)(session, operation_state.as_mut_ptr(), operation_state.len() as CK_ULONG, encryption_key.unwrap_or(0), authentication_key.unwrap_or(0)) { CKR_OK => Ok(()), err => Err(Error::Pkcs11(err)), @@ -558,15 +561,15 @@ impl Ctx { } } - // Some dongle drivers (such as Safenet) allow NUL bytes in PINs, and fail - // login if a NUL containing PIN is truncated. Combined with poor PIN gen - // algorithms which insert NULs into the PIN, you might need a way to supply - // raw bytes for a PIN, instead of converting from a UTF8 string as per spec - pub fn login_with_raw<'a>(&self, session: CK_SESSION_HANDLE, user_type: CK_USER_TYPE, pin: Option<&Vec>) -> Result<(), Error> { + /// Some dongle drivers (such as Safenet) allow NUL bytes in PINs, and fail + /// login if a NUL containing PIN is truncated. Combined with poor PIN gen + /// algorithms which insert NULs into the PIN, you might need a way to supply + /// raw bytes for a PIN, instead of converting from a UTF8 string as per spec + pub fn login_with_raw(&self, session: CK_SESSION_HANDLE, user_type: CK_USER_TYPE, pin: Option<&[CK_BYTE]>) -> Result<(), Error> { self.initialized()?; match pin { Some(pin) => { - let mut pin = pin.clone(); + let mut pin = pin.to_vec(); match (self.C_Login)(session, user_type, pin.as_mut_ptr(), pin.len() as CK_ULONG) { CKR_OK => Ok(()), err => Err(Error::Pkcs11(err)), @@ -587,9 +590,9 @@ impl Ctx { } } - pub fn create_object(&self, session: CK_SESSION_HANDLE, template: &Vec) -> Result { + pub fn create_object(&self, session: CK_SESSION_HANDLE, template: &[CK_ATTRIBUTE]) -> Result { self.initialized()?; - let mut template = template.clone(); + let mut template = template.to_vec(); let mut oh: CK_OBJECT_HANDLE = CK_INVALID_HANDLE; match (self.C_CreateObject)(session, template.as_mut_ptr(), template.len() as CK_ULONG, &mut oh) { CKR_OK => Ok(oh), @@ -597,9 +600,9 @@ impl Ctx { } } - pub fn copy_object(&self, session: CK_SESSION_HANDLE, object: CK_OBJECT_HANDLE, template: &Vec) -> Result { + pub fn copy_object(&self, session: CK_SESSION_HANDLE, object: CK_OBJECT_HANDLE, template: &[CK_ATTRIBUTE]) -> Result { self.initialized()?; - let mut template = template.clone(); + let mut template = template.to_vec(); let mut oh: CK_OBJECT_HANDLE = CK_INVALID_HANDLE; match (self.C_CopyObject)(session, object, template.as_mut_ptr(), template.len() as CK_ULONG, &mut oh) { CKR_OK => Ok(oh), @@ -642,18 +645,18 @@ impl Ctx { } } - pub fn set_attribute_value(&self, session: CK_SESSION_HANDLE, object: CK_OBJECT_HANDLE, template: &Vec) -> Result<(), Error> { + pub fn set_attribute_value(&self, session: CK_SESSION_HANDLE, object: CK_OBJECT_HANDLE, template: &[CK_ATTRIBUTE]) -> Result<(), Error> { self.initialized()?; - let mut template = template.clone(); + let mut template = template.to_vec(); match (self.C_SetAttributeValue)(session, object, template.as_mut_ptr(), template.len() as CK_ULONG) { CKR_OK => Ok(()), err => Err(Error::Pkcs11(err)), } } - pub fn find_objects_init(&self, session: CK_SESSION_HANDLE, template: &Vec) -> Result<(), Error> { + pub fn find_objects_init(&self, session: CK_SESSION_HANDLE, template: &[CK_ATTRIBUTE]) -> Result<(), Error> { self.initialized()?; - let mut template = template.clone(); + let mut template = template.to_vec(); match (self.C_FindObjectsInit)(session, template.as_mut_ptr(), template.len() as CK_ULONG) { CKR_OK => Ok(()), err => Err(Error::Pkcs11(err)), @@ -692,9 +695,9 @@ impl Ctx { } } - pub fn encrypt(&self, session: CK_SESSION_HANDLE, data: &Vec) -> Result, Error> { + pub fn encrypt(&self, session: CK_SESSION_HANDLE, data: &[CK_BYTE]) -> Result, Error> { self.initialized()?; - let mut data = data.clone(); + let mut data = data.to_vec(); let mut encryptedDataLen: CK_ULONG = 0; match (self.C_Encrypt)(session, data.as_mut_ptr(), data.len() as CK_ULONG, ptr::null_mut(), &mut encryptedDataLen) { CKR_OK => { @@ -713,9 +716,9 @@ impl Ctx { } } - pub fn encrypt_update(&self, session: CK_SESSION_HANDLE, part: &Vec) -> Result, Error> { + pub fn encrypt_update(&self, session: CK_SESSION_HANDLE, part: &[CK_BYTE]) -> Result, Error> { self.initialized()?; - let mut part = part.clone(); + let mut part = part.to_vec(); let mut encryptedPartLen: CK_ULONG = 0; match (self.C_EncryptUpdate)(session, part.as_mut_ptr(), part.len() as CK_ULONG, ptr::null_mut(), &mut encryptedPartLen) { CKR_OK => { @@ -767,9 +770,9 @@ impl Ctx { } } - pub fn decrypt(&self, session: CK_SESSION_HANDLE, encryptedData: &Vec) -> Result, Error> { + pub fn decrypt(&self, session: CK_SESSION_HANDLE, encryptedData: &[CK_BYTE]) -> Result, Error> { self.initialized()?; - let mut encrypted_data = encryptedData.clone(); + let mut encrypted_data = encryptedData.to_vec(); let mut dataLen: CK_ULONG = 0; match (self.C_Decrypt)(session, encrypted_data.as_mut_ptr(), encrypted_data.len() as CK_ULONG, ptr::null_mut(), &mut dataLen) { CKR_OK => { @@ -788,14 +791,14 @@ impl Ctx { } } - pub fn decrypt_update(&self, session: CK_SESSION_HANDLE, encryptedPart: &Vec) -> Result, Error> { + pub fn decrypt_update(&self, session: CK_SESSION_HANDLE, encryptedPart: &[CK_BYTE]) -> Result, Error> { self.initialized()?; - let mut encrypted_part = encryptedPart.clone(); + let mut encrypted_part = encryptedPart.to_vec(); let mut partLen: CK_ULONG = 0; match (self.C_DecryptUpdate)(session, encrypted_part.as_mut_ptr(), encrypted_part.len() as CK_ULONG, ptr::null_mut(), &mut partLen) { CKR_OK => { let mut part: Vec = Vec::with_capacity(partLen as usize); - match (self.C_Decrypt)(session, encrypted_part.as_mut_ptr(), encrypted_part.len() as CK_ULONG, part.as_mut_ptr(), &mut partLen) { + match (self.C_DecryptUpdate)(session, encrypted_part.as_mut_ptr(), encrypted_part.len() as CK_ULONG, part.as_mut_ptr(), &mut partLen) { CKR_OK => { unsafe { part.set_len(partLen as usize); @@ -842,9 +845,9 @@ impl Ctx { } } - pub fn digest(&self, session: CK_SESSION_HANDLE, data: &Vec) -> Result, Error> { + pub fn digest(&self, session: CK_SESSION_HANDLE, data: &[CK_BYTE]) -> Result, Error> { self.initialized()?; - let mut data = data.clone(); + let mut data = data.to_vec(); let mut digestLen: CK_ULONG = 0; match (self.C_Digest)(session, data.as_mut_ptr(), data.len() as CK_ULONG, ptr::null_mut(), &mut digestLen) { CKR_OK => { @@ -863,8 +866,8 @@ impl Ctx { } } - pub fn digest_update(&self, session: CK_SESSION_HANDLE, part: &Vec) -> Result<(), Error> { - let mut part = part.clone(); + pub fn digest_update(&self, session: CK_SESSION_HANDLE, part: &[CK_BYTE]) -> Result<(), Error> { + let mut part = part.to_vec(); match (self.C_DigestUpdate)(session, part.as_mut_ptr(), part.len() as CK_ULONG) { CKR_OK => Ok(()), err => Err(Error::Pkcs11(err)), @@ -908,9 +911,9 @@ impl Ctx { } } - pub fn sign(&self, session: CK_SESSION_HANDLE, data: &Vec) -> Result, Error> { + pub fn sign(&self, session: CK_SESSION_HANDLE, data: &[CK_BYTE]) -> Result, Error> { self.initialized()?; - let mut data = data.clone(); + let mut data = data.to_vec(); let mut signatureLen: CK_ULONG = 0; match (self.C_Sign)(session, data.as_mut_ptr(), data.len() as CK_ULONG, ptr::null_mut(), &mut signatureLen) { CKR_OK => { @@ -929,9 +932,9 @@ impl Ctx { } } - pub fn sign_update(&self, session: CK_SESSION_HANDLE, part: &Vec) -> Result<(), Error> { + pub fn sign_update(&self, session: CK_SESSION_HANDLE, part: &[CK_BYTE]) -> Result<(), Error> { self.initialized()?; - let mut part = part.clone(); + let mut part = part.to_vec(); match (self.C_SignUpdate)(session, part.as_mut_ptr(), part.len() as CK_ULONG) { CKR_OK => Ok(()), err => Err(Error::Pkcs11(err)), @@ -967,9 +970,9 @@ impl Ctx { } } - pub fn sign_recover(&self, session: CK_SESSION_HANDLE, data: &Vec) -> Result, Error> { + pub fn sign_recover(&self, session: CK_SESSION_HANDLE, data: &[CK_BYTE]) -> Result, Error> { self.initialized()?; - let mut data = data.clone(); + let mut data = data.to_vec(); let mut signatureLen: CK_ULONG = 0; match (self.C_SignRecover)(session, data.as_mut_ptr(), data.len() as CK_ULONG, ptr::null_mut(), &mut signatureLen) { CKR_OK => { @@ -997,28 +1000,28 @@ impl Ctx { } } - pub fn verify(&self, session: CK_SESSION_HANDLE, data: &Vec, signature: &Vec) -> Result<(), Error> { + pub fn verify(&self, session: CK_SESSION_HANDLE, data: &[CK_BYTE], signature: &[CK_BYTE]) -> Result<(), Error> { self.initialized()?; - let mut data = data.clone(); - let mut signature = signature.clone(); + let mut data = data.to_vec(); + let mut signature = signature.to_vec(); match (self.C_Verify)(session, data.as_mut_ptr(), data.len() as CK_ULONG, signature.as_mut_ptr(), signature.len() as CK_ULONG) { CKR_OK => Ok(()), err => Err(Error::Pkcs11(err)), } } - pub fn verify_update(&self, session: CK_SESSION_HANDLE, part: &Vec) -> Result<(), Error> { + pub fn verify_update(&self, session: CK_SESSION_HANDLE, part: &[CK_BYTE]) -> Result<(), Error> { self.initialized()?; - let mut part = part.clone(); + let mut part = part.to_vec(); match (self.C_VerifyUpdate)(session, part.as_mut_ptr(), part.len() as CK_ULONG) { CKR_OK => Ok(()), err => Err(Error::Pkcs11(err)), } } - pub fn verify_final(&self, session: CK_SESSION_HANDLE, signature: &Vec) -> Result<(), Error> { + pub fn verify_final(&self, session: CK_SESSION_HANDLE, signature: &[CK_BYTE]) -> Result<(), Error> { self.initialized()?; - let mut signature = signature.clone(); + let mut signature = signature.to_vec(); match (self.C_VerifyFinal)(session, signature.as_mut_ptr(), signature.len() as CK_ULONG) { CKR_OK => Ok(()), err => Err(Error::Pkcs11(err)), @@ -1034,9 +1037,9 @@ impl Ctx { } } - pub fn verify_recover(&self, session: CK_SESSION_HANDLE, signature: &Vec) -> Result, Error> { + pub fn verify_recover(&self, session: CK_SESSION_HANDLE, signature: &[CK_BYTE]) -> Result, Error> { self.initialized()?; - let mut signature = signature.clone(); + let mut signature = signature.to_vec(); let mut dataLen: CK_ULONG = 0; match (self.C_VerifyRecover)(session, signature.as_mut_ptr(), signature.len() as CK_ULONG, ptr::null_mut(), &mut dataLen) { CKR_OK => { @@ -1055,9 +1058,9 @@ impl Ctx { } } - pub fn digest_encrypt_update(&self, session: CK_SESSION_HANDLE, part: &Vec) -> Result, Error> { + pub fn digest_encrypt_update(&self, session: CK_SESSION_HANDLE, part: &[CK_BYTE]) -> Result, Error> { self.initialized()?; - let mut part = part.clone(); + let mut part = part.to_vec(); let mut encryptedPartLen: CK_ULONG = 0; match (self.C_DigestEncryptUpdate)(session, part.as_mut_ptr(), part.len() as CK_ULONG, ptr::null_mut(), &mut encryptedPartLen) { CKR_OK => { @@ -1076,9 +1079,9 @@ impl Ctx { } } - pub fn decrypt_digest_update(&self, session: CK_SESSION_HANDLE, encryptedPart: &Vec) -> Result, Error> { + pub fn decrypt_digest_update(&self, session: CK_SESSION_HANDLE, encryptedPart: &[CK_BYTE]) -> Result, Error> { self.initialized()?; - let mut encrypted_part = encryptedPart.clone(); + let mut encrypted_part = encryptedPart.to_vec(); let mut partLen: CK_ULONG = 0; match (self.C_DecryptDigestUpdate)(session, encrypted_part.as_mut_ptr(), encrypted_part.len() as CK_ULONG, ptr::null_mut(), &mut partLen) { CKR_OK => { @@ -1097,9 +1100,9 @@ impl Ctx { } } - pub fn sign_encrypt_update(&self, session: CK_SESSION_HANDLE, part: &Vec) -> Result, Error> { + pub fn sign_encrypt_update(&self, session: CK_SESSION_HANDLE, part: &[CK_BYTE]) -> Result, Error> { self.initialized()?; - let mut part = part.clone(); + let mut part = part.to_vec(); let mut encryptedPartLen: CK_ULONG = 0; match (self.C_SignEncryptUpdate)(session, part.as_mut_ptr(), part.len() as CK_ULONG, ptr::null_mut(), &mut encryptedPartLen) { CKR_OK => { @@ -1120,7 +1123,7 @@ impl Ctx { pub fn decrypt_verify_update(&self, session: CK_SESSION_HANDLE, encryptedPart: Vec) -> Result, Error> { self.initialized()?; - let mut encrypted_part = encryptedPart.clone(); + let mut encrypted_part = encryptedPart; let mut partLen: CK_ULONG = 0; match (self.C_DecryptVerifyUpdate)(session, encrypted_part.as_mut_ptr(), encrypted_part.len() as CK_ULONG, ptr::null_mut(), &mut partLen) { CKR_OK => { @@ -1139,10 +1142,10 @@ impl Ctx { } } - pub fn generate_key(&self, session: CK_SESSION_HANDLE, mechanism: &CK_MECHANISM, template: &Vec) -> Result { + pub fn generate_key(&self, session: CK_SESSION_HANDLE, mechanism: &CK_MECHANISM, template: &[CK_ATTRIBUTE]) -> Result { self.initialized()?; let mut mechanism = *mechanism; - let mut template = template.clone(); + let mut template = template.to_vec(); let mut object: CK_OBJECT_HANDLE = CK_INVALID_HANDLE; match (self.C_GenerateKey)(session, &mut mechanism, template.as_mut_ptr(), template.len() as CK_ULONG, &mut object) { CKR_OK => Ok(object), @@ -1154,13 +1157,13 @@ impl Ctx { &self, session: CK_SESSION_HANDLE, mechanism: &CK_MECHANISM, - publicKeyTemplate: &Vec, - privateKeyTemplate: &Vec, + publicKeyTemplate: &[CK_ATTRIBUTE], + privateKeyTemplate: &[CK_ATTRIBUTE], ) -> Result<(CK_OBJECT_HANDLE, CK_OBJECT_HANDLE), Error> { self.initialized()?; let mut mechanism = *mechanism; - let mut public_key_template = publicKeyTemplate.clone(); - let mut private_key_template = privateKeyTemplate.clone(); + let mut public_key_template = publicKeyTemplate.to_vec(); + let mut private_key_template = privateKeyTemplate.to_vec(); let mut pubOh: CK_OBJECT_HANDLE = CK_INVALID_HANDLE; let mut privOh: CK_OBJECT_HANDLE = CK_INVALID_HANDLE; match (self.C_GenerateKeyPair)( @@ -1206,13 +1209,13 @@ impl Ctx { session: CK_SESSION_HANDLE, mechanism: &CK_MECHANISM, unwrappingKey: CK_OBJECT_HANDLE, - wrappedKey: &Vec, - template: &Vec, + wrappedKey: &[CK_BYTE], + template: &[CK_ATTRIBUTE], ) -> Result { self.initialized()?; let mut mechanism= *mechanism; - let mut wrapped_key = wrappedKey.clone(); - let mut template = template.clone(); + let mut wrapped_key = wrappedKey.to_vec(); + let mut template = template.to_vec(); let mut oh: CK_OBJECT_HANDLE = CK_INVALID_HANDLE; match (self.C_UnwrapKey)( session, @@ -1229,10 +1232,10 @@ impl Ctx { } } - pub fn derive_key(&self, session: CK_SESSION_HANDLE, mechanism: &CK_MECHANISM, baseKey: CK_OBJECT_HANDLE, template: &Vec) -> Result { + pub fn derive_key(&self, session: CK_SESSION_HANDLE, mechanism: &CK_MECHANISM, baseKey: CK_OBJECT_HANDLE, template: &[CK_ATTRIBUTE]) -> Result { self.initialized()?; let mut mechanism = *mechanism; - let mut template = template.clone(); + let mut template = template.to_vec(); let mut oh: CK_OBJECT_HANDLE = CK_INVALID_HANDLE; match (self.C_DeriveKey)(session, &mut mechanism, baseKey, template.as_mut_ptr(), template.len() as CK_ULONG, &mut oh) { CKR_OK => Ok(oh), @@ -1240,8 +1243,8 @@ impl Ctx { } } - pub fn seed_random(&self, session: CK_SESSION_HANDLE, seed: &Vec) -> Result<(), Error> { - let mut seed = seed.clone(); + pub fn seed_random(&self, session: CK_SESSION_HANDLE, seed: &[CK_BYTE]) -> Result<(), Error> { + let mut seed = seed.to_vec(); match (self.C_SeedRandom)(session, seed.as_mut_ptr(), seed.len() as CK_ULONG) { CKR_OK => Ok(()), err => Err(Error::Pkcs11(err)), diff --git a/third_party/rust/pkcs11/src/tests.rs b/third_party/rust/pkcs11/src/tests.rs index bc0da16f8c1c..f85eaaa97894 100644 --- a/third_party/rust/pkcs11/src/tests.rs +++ b/third_party/rust/pkcs11/src/tests.rs @@ -32,7 +32,7 @@ fn pkcs11_module_name() -> PathBuf { let default_path = option_env!("PKCS11_SOFTHSM2_MODULE") .unwrap_or("/usr/local/lib/softhsm/libsofthsm2.so"); let path = env::var_os("PKCS11_SOFTHSM2_MODULE") - .unwrap_or(default_path.into()); + .unwrap_or_else(|| default_path.into()); let path_buf = PathBuf::from(path); if !path_buf.exists() { @@ -169,7 +169,7 @@ fn ctx_get_slot_list() { fn ctx_get_slot_infos() { let ctx = Ctx::new_and_initialize(pkcs11_module_name()).unwrap(); let slots = ctx.get_slot_list(false).unwrap(); - for slot in slots[..1].into_iter() { + for slot in slots[..1].iter() { let slot = *slot; let res = ctx.get_slot_info(slot); assert!( @@ -188,7 +188,7 @@ fn ctx_get_slot_infos() { fn ctx_get_token_infos() { let ctx = Ctx::new_and_initialize(pkcs11_module_name()).unwrap(); let slots = ctx.get_slot_list(false).unwrap(); - for slot in slots[..1].into_iter() { + for slot in slots[..1].iter() { let slot = *slot; let res = ctx.get_token_info(slot); assert!( @@ -207,7 +207,7 @@ fn ctx_get_token_infos() { fn ctx_get_mechanism_lists() { let ctx = Ctx::new_and_initialize(pkcs11_module_name()).unwrap(); let slots = ctx.get_slot_list(false).unwrap(); - for slot in slots[..1].into_iter() { + for slot in slots[..1].iter() { let slot = *slot; let res = ctx.get_mechanism_list(slot); assert!( @@ -226,7 +226,7 @@ fn ctx_get_mechanism_lists() { fn ctx_get_mechanism_infos() { let ctx = Ctx::new_and_initialize(pkcs11_module_name()).unwrap(); let slots = ctx.get_slot_list(false).unwrap(); - for slot in slots[..1].into_iter() { + for slot in slots[..1].iter() { let slot = *slot; let mechanisms = ctx.get_mechanism_list(slot).unwrap(); for mechanism in mechanisms { @@ -251,7 +251,7 @@ fn ctx_init_token() { let slots = ctx.get_slot_list(false).unwrap(); let pin = Some("1234"); const LABEL: &str = "rust-unit-test"; - for slot in slots[..1].into_iter() { + for slot in slots[..1].iter() { let slot = *slot; let res = ctx.init_token(slot, pin, LABEL); assert!( @@ -277,7 +277,7 @@ fn ctx_init_pin() { let slots = ctx.get_slot_list(false).unwrap(); let pin = Some("1234"); const LABEL: &str = "rust-unit-test"; - for slot in slots[..1].into_iter() { + for slot in slots[..1].iter() { let slot = *slot; ctx.init_token(slot, pin, LABEL).unwrap(); let sh = ctx @@ -304,7 +304,7 @@ fn ctx_set_pin() { let pin = Some("1234"); let new_pin = Some("1234"); const LABEL: &str = "rust-unit-test"; - for slot in slots[..1].into_iter() { + for slot in slots[..1].iter() { let slot = *slot; ctx.init_token(slot, pin, LABEL).unwrap(); let sh = ctx @@ -331,7 +331,7 @@ fn ctx_open_session() { let slots = ctx.get_slot_list(false).unwrap(); let pin = Some("1234"); const LABEL: &str = "rust-unit-test"; - for slot in slots[..1].into_iter() { + for slot in slots[..1].iter() { let slot = *slot; ctx.init_token(slot, pin, LABEL).unwrap(); let res = ctx.open_session(slot, CKF_SERIAL_SESSION, None, None); @@ -353,7 +353,7 @@ fn ctx_close_session() { let slots = ctx.get_slot_list(false).unwrap(); let pin = Some("1234"); const LABEL: &str = "rust-unit-test"; - for slot in slots[..1].into_iter() { + for slot in slots[..1].iter() { let slot = *slot; ctx.init_token(slot, pin, LABEL).unwrap(); let sh = ctx @@ -377,7 +377,7 @@ fn ctx_close_all_sessions() { let slots = ctx.get_slot_list(false).unwrap(); let pin = Some("1234"); const LABEL: &str = "rust-unit-test"; - for slot in slots[..1].into_iter() { + for slot in slots[..1].iter() { let slot = *slot; ctx.init_token(slot, pin, LABEL).unwrap(); ctx @@ -401,7 +401,7 @@ fn ctx_get_session_info() { let slots = ctx.get_slot_list(false).unwrap(); let pin = Some("1234"); const LABEL: &str = "rust-unit-test"; - for slot in slots[..1].into_iter() { + for slot in slots[..1].iter() { let slot = *slot; ctx.init_token(slot, pin, LABEL).unwrap(); let sh = ctx @@ -426,7 +426,7 @@ fn ctx_login() { let slots = ctx.get_slot_list(false).unwrap(); let pin = Some("1234"); const LABEL: &str = "rust-unit-test"; - for slot in slots[..1].into_iter() { + for slot in slots[..1].iter() { let slot = *slot; ctx.init_token(slot, pin, LABEL).unwrap(); let sh = ctx @@ -451,7 +451,7 @@ fn ctx_logout() { let slots = ctx.get_slot_list(false).unwrap(); let pin = Some("1234"); const LABEL: &str = "rust-unit-test"; - for slot in slots[..1].into_iter() { + for slot in slots[..1].iter() { let slot = *slot; ctx.init_token(slot, pin, LABEL).unwrap(); let sh = ctx @@ -731,15 +731,18 @@ fn ctx_get_attribute_value() { ]; println!("Template: {:?}", template); { - let res = ctx.get_attribute_value(sh, oh, &template); - assert!( - res.is_ok(), - "failed to call C_GetAttributeValue({}, {}, {:?}): {}", - sh, - oh, - &template, - res.unwrap_err() - ); + let res = ctx.get_attribute_value(sh, oh, &mut template); + if !res.is_ok() { + // Doing this not as an assert so we can both unwrap_err with the mut template and re-borrow template + let err = res.unwrap_err(); + panic!( + "failed to call C_GetAttributeValue({}, {}, {:?}): {}", + sh, + oh, + &template, + err + ); + } let (rv, _) = res.unwrap(); println!("CK_RV: 0x{:x}, Template: {:?}", rv, &template); } @@ -753,15 +756,18 @@ fn ctx_get_attribute_value() { template[2].set_string(&label); template[3].set_bytes(&value.as_slice()); - let res = ctx.get_attribute_value(sh, oh, &template); - assert!( - res.is_ok(), - "failed to call C_GetAttributeValue({}, {}, {:?}): {}", - sh, - oh, - &template, - res.unwrap_err() - ); + let res = ctx.get_attribute_value(sh, oh, &mut template); + if !res.is_ok() { + // Doing this not as an assert so we can both unwrap_err with the mut template and re-borrow template + let err = res.unwrap_err(); + panic!( + "failed to call C_GetAttributeValue({}, {}, {:?}): {}", + sh, + oh, + &template, + err + ); + } let (rv, _) = res.unwrap(); println!("CK_RV: 0x{:x}, Retrieved Attributes: {:?}", rv, &template); @@ -792,8 +798,8 @@ fn ctx_set_attribute_value() { ); let str: Vec = Vec::from("aaaaaaaaaaaaaaaa"); - let template2 = vec![CK_ATTRIBUTE::new(CKA_LABEL).with_bytes(&str.as_slice())]; - ctx.get_attribute_value(sh, oh, &template2).unwrap(); + let mut template2 = vec![CK_ATTRIBUTE::new(CKA_LABEL).with_bytes(&str.as_slice())]; + ctx.get_attribute_value(sh, oh, &mut template2).unwrap(); assert_eq!(Vec::from("Hello New World!"), template2[0].get_bytes()); } @@ -864,7 +870,7 @@ fn ctx_generate_key() { let mechanism = CK_MECHANISM { mechanism: CKM_AES_KEY_GEN, - pParameter: ptr::null(), + pParameter: ptr::null_mut(), ulParameterLen: 0, }; @@ -931,7 +937,7 @@ fn ctx_generate_key_pair() { let mechanism = CK_MECHANISM { mechanism: CKM_RSA_PKCS_KEY_PAIR_GEN, - pParameter: ptr::null(), + pParameter: ptr::null_mut(), ulParameterLen: 0, }; @@ -1026,7 +1032,7 @@ fn fixture_token_and_secret_keys( { let mechanism = CK_MECHANISM { mechanism: CKM_AES_KEY_GEN, - pParameter: ptr::null(), + pParameter: ptr::null_mut(), ulParameterLen: 0, }; @@ -1064,7 +1070,7 @@ fn fixture_token_and_secret_keys( { let mechanism = CK_MECHANISM { mechanism: CKM_AES_KEY_GEN, - pParameter: ptr::null(), + pParameter: ptr::null_mut(), ulParameterLen: 0, }; @@ -1124,7 +1130,7 @@ fn fixture_key_pair( ) -> Result<(CK_OBJECT_HANDLE, CK_OBJECT_HANDLE), Error> { let mechanism = CK_MECHANISM { mechanism: CKM_RSA_PKCS_KEY_PAIR_GEN, - pParameter: ptr::null(), + pParameter: ptr::null_mut(), ulParameterLen: 0, }; @@ -1185,7 +1191,7 @@ fn fixture_dh_key_pair( ) -> Result<(CK_OBJECT_HANDLE, CK_OBJECT_HANDLE), Error> { let mechanism = CK_MECHANISM { mechanism: CKM_DH_PKCS_KEY_PAIR_GEN, - pParameter: ptr::null(), + pParameter: ptr::null_mut(), ulParameterLen: 0, }; //[]*pkcs11.Attribute{ @@ -1266,7 +1272,7 @@ fn ctx_wrap_key() { // using the default IV let mechanism = CK_MECHANISM { mechanism: CKM_AES_KEY_WRAP_PAD, - pParameter: ptr::null(), + pParameter: ptr::null_mut(), ulParameterLen: 0, }; @@ -1296,7 +1302,7 @@ fn ctx_unwrap_key() { // using the default IV let mechanism = CK_MECHANISM { mechanism: CKM_AES_KEY_WRAP_PAD, - pParameter: ptr::null(), + pParameter: ptr::null_mut(), ulParameterLen: 0, }; @@ -1364,18 +1370,18 @@ fn ctx_derive_key() { // 2. retrieve the public key bytes from both let mut template = vec![CK_ATTRIBUTE::new(CKA_VALUE)]; - ctx.get_attribute_value(sh, pubOh1, &template).unwrap(); + ctx.get_attribute_value(sh, pubOh1, &mut template).unwrap(); let value: Vec = Vec::with_capacity(template[0].ulValueLen); template[0].set_bytes(&value.as_slice()); - ctx.get_attribute_value(sh, pubOh1, &template).unwrap(); + ctx.get_attribute_value(sh, pubOh1, &mut template).unwrap(); let pub1Bytes = template[0].get_bytes(); let mut template = vec![CK_ATTRIBUTE::new(CKA_VALUE)]; - ctx.get_attribute_value(sh, pubOh2, &template).unwrap(); + ctx.get_attribute_value(sh, pubOh2, &mut template).unwrap(); let value: Vec = Vec::with_capacity(template[0].ulValueLen); template[0].set_bytes(&value.as_slice()); - ctx.get_attribute_value(sh, pubOh2, &template).unwrap(); + ctx.get_attribute_value(sh, pubOh2, &mut template).unwrap(); let pub2Bytes = template[0].get_bytes(); @@ -1445,18 +1451,18 @@ fn ctx_derive_key() { // 5. retrieve the derived private keys from both let mut template = vec![CK_ATTRIBUTE::new(CKA_VALUE)]; - ctx.get_attribute_value(sh, secOh1, &template).unwrap(); + ctx.get_attribute_value(sh, secOh1, &mut template).unwrap(); let value: Vec = Vec::with_capacity(template[0].ulValueLen); template[0].set_bytes(&value.as_slice()); - ctx.get_attribute_value(sh, secOh1, &template).unwrap(); + ctx.get_attribute_value(sh, secOh1, &mut template).unwrap(); let sec1Bytes = template[0].get_bytes(); let mut template = vec![CK_ATTRIBUTE::new(CKA_VALUE)]; - ctx.get_attribute_value(sh, secOh2, &template).unwrap(); + ctx.get_attribute_value(sh, secOh2, &mut template).unwrap(); let value: Vec = Vec::with_capacity(template[0].ulValueLen); template[0].set_bytes(&value.as_slice()); - ctx.get_attribute_value(sh, secOh2, &template).unwrap(); + ctx.get_attribute_value(sh, secOh2, &mut template).unwrap(); let sec2Bytes = template[0].get_bytes(); diff --git a/third_party/rust/pkcs11/src/types.rs b/third_party/rust/pkcs11/src/types.rs index 9dd128933430..f39472f5c8c0 100644 --- a/third_party/rust/pkcs11/src/types.rs +++ b/third_party/rust/pkcs11/src/types.rs @@ -145,8 +145,8 @@ pub const CKN_OTP_CHANGED: CK_NOTIFICATION = 1; pub type CK_SLOT_ID = CK_ULONG; pub type CK_SLOT_ID_PTR = *mut CK_SLOT_ID; -/// CK_SLOT_INFO provides information about a slot cryptoki_aligned! { + /// CK_SLOT_INFO provides information about a slot pub struct CK_SLOT_INFO { /// slotDescription and manufacturerID have been changed from /// CK_CHAR to CK_UTF8CHAR for v2.10 @@ -628,9 +628,9 @@ pub const CKA_ALLOWED_MECHANISMS: CK_ATTRIBUTE_TYPE = (CKF_ARRAY_ATTRIBUTE | 0x0 pub const CKA_VENDOR_DEFINED: CK_ATTRIBUTE_TYPE = 0x80000000; -/// CK_ATTRIBUTE is a structure that includes the type, length -/// and value of an attribute cryptoki_aligned! { + /// CK_ATTRIBUTE is a structure that includes the type, length + /// and value of an attribute #[derive(Copy)] pub struct CK_ATTRIBUTE { pub attrType: CK_ATTRIBUTE_TYPE, @@ -669,7 +669,7 @@ impl std::fmt::Debug for CK_ATTRIBUTE { impl CK_ATTRIBUTE { pub fn new(attrType: CK_ATTRIBUTE_TYPE) -> Self { Self { - attrType: attrType, + attrType, pValue: ptr::null_mut(), ulValueLen: 0, } @@ -727,14 +727,14 @@ impl CK_ATTRIBUTE { unsafe { mem::transmute_copy(&*self.pValue) } } - pub fn with_biginteger(mut self, val: &Vec) -> Self { - self.pValue = val.as_slice().as_ptr() as CK_VOID_PTR; + pub fn with_biginteger(mut self, val: &[u8]) -> Self { + self.pValue = val.as_ptr() as CK_VOID_PTR; self.ulValueLen = val.len() as CK_ULONG; self } - pub fn set_biginteger(&mut self, val: &Vec) { - self.pValue = val.as_slice().as_ptr() as CK_VOID_PTR; + pub fn set_biginteger(&mut self, val: &[u8]) { + self.pValue = val.as_ptr() as CK_VOID_PTR; if self.ulValueLen == 0 { self.ulValueLen = val.len() as CK_ULONG; } @@ -760,7 +760,7 @@ impl CK_ATTRIBUTE { pub fn get_bytes(&self) -> Vec { let slice = unsafe { slice::from_raw_parts(self.pValue as CK_BYTE_PTR, self.ulValueLen as usize) }; - Vec::from(slice).clone() + Vec::from(slice) } pub fn with_string(mut self, str: &String) -> Self { @@ -778,7 +778,7 @@ impl CK_ATTRIBUTE { pub fn get_string(&self) -> String { let slice = unsafe { slice::from_raw_parts(self.pValue as CK_BYTE_PTR, self.ulValueLen as usize) }; - String::from_utf8_lossy(slice).into_owned().clone() + String::from_utf8_lossy(slice).into_owned() } pub fn with_date(mut self, date: &CK_DATE) -> Self { @@ -831,8 +831,8 @@ impl CK_ATTRIBUTE { // } //} -/// CK_DATE is a structure that defines a date cryptoki_aligned! { + /// CK_DATE is a structure that defines a date #[derive(Debug, Default, Copy)] pub struct CK_DATE { /// the year ("1900" - "9999") @@ -1245,10 +1245,9 @@ pub const CKM_VENDOR_DEFINED: CK_MECHANISM_TYPE = 0x80000000; pub type CK_MECHANISM_TYPE_PTR = *mut CK_MECHANISM_TYPE; - -/// CK_MECHANISM is a structure that specifies a particular -/// mechanism cryptoki_aligned! { + /// CK_MECHANISM is a structure that specifies a particular + /// mechanism #[derive(Debug, Copy)] pub struct CK_MECHANISM { pub mechanism: CK_MECHANISM_TYPE, @@ -1261,9 +1260,9 @@ packed_clone!(CK_MECHANISM); pub type CK_MECHANISM_PTR = *mut CK_MECHANISM; -/// CK_MECHANISM_INFO provides information about a particular -/// mechanism cryptoki_aligned! { + /// CK_MECHANISM_INFO provides information about a particular + /// mechanism #[derive(Debug, Default, Copy)] pub struct CK_MECHANISM_INFO { pub ulMinKeySize: CK_ULONG, @@ -1405,10 +1404,10 @@ pub const CKR_VENDOR_DEFINED: CK_RV = 0x80000000; /// CK_NOTIFY is an application callback that processes events pub type CK_NOTIFY = Option CK_RV>; -/// CK_FUNCTION_LIST is a structure holding a Cryptoki spec -/// version and pointers of appropriate types to all the -/// Cryptoki functions cryptoki_aligned! { + /// CK_FUNCTION_LIST is a structure holding a Cryptoki spec + /// version and pointers of appropriate types to all the + /// Cryptoki functions #[derive(Debug, Copy)] pub struct CK_FUNCTION_LIST { pub version: CK_VERSION, @@ -1498,9 +1497,9 @@ pub type CK_LOCKMUTEX = Option CK_RV>; /// mutex pub type CK_UNLOCKMUTEX = Option CK_RV>; -/// CK_C_INITIALIZE_ARGS provides the optional arguments to -/// C_Initialize cryptoki_aligned! { + /// CK_C_INITIALIZE_ARGS provides the optional arguments to + /// C_Initialize #[derive(Debug, Copy)] pub struct CK_C_INITIALIZE_ARGS { pub CreateMutex: CK_CREATEMUTEX, @@ -1515,6 +1514,12 @@ packed_clone!(CK_C_INITIALIZE_ARGS); // TODO: we need to make this the default and implement a new // function +impl Default for CK_C_INITIALIZE_ARGS { + fn default() -> Self { + Self::new() + } +} + impl CK_C_INITIALIZE_ARGS { pub fn new() -> CK_C_INITIALIZE_ARGS { CK_C_INITIALIZE_ARGS { @@ -1561,9 +1566,9 @@ pub type CK_RSA_PKCS_OAEP_SOURCE_TYPE_PTR = *mut CK_RSA_PKCS_OAEP_SOURCE_TYPE; /// The following encoding parameter sources are defined pub const CKZ_DATA_SPECIFIED: CK_RSA_PKCS_OAEP_SOURCE_TYPE = 0x00000001; -/// CK_RSA_PKCS_OAEP_PARAMS provides the parameters to the -/// CKM_RSA_PKCS_OAEP mechanism. cryptoki_aligned! { + /// CK_RSA_PKCS_OAEP_PARAMS provides the parameters to the + /// CKM_RSA_PKCS_OAEP mechanism. #[derive(Debug, Copy)] pub struct CK_RSA_PKCS_OAEP_PARAMS { pub hashAlg: CK_MECHANISM_TYPE, @@ -1577,9 +1582,9 @@ packed_clone!(CK_RSA_PKCS_OAEP_PARAMS); pub type CK_RSA_PKCS_OAEP_PARAMS_PTR = *mut CK_RSA_PKCS_OAEP_PARAMS; -/// CK_RSA_PKCS_PSS_PARAMS provides the parameters to the -/// CKM_RSA_PKCS_PSS mechanism(s). cryptoki_aligned! { + /// CK_RSA_PKCS_PSS_PARAMS provides the parameters to the + /// CKM_RSA_PKCS_PSS mechanism(s). #[derive(Debug, Copy)] pub struct CK_RSA_PKCS_PSS_PARAMS { pub hashAlg: CK_MECHANISM_TYPE, @@ -1606,10 +1611,10 @@ pub const CKD_SHA384_KDF: CK_X9_42_DH_KDF_TYPE = 0x00000007; pub const CKD_SHA512_KDF: CK_X9_42_DH_KDF_TYPE = 0x00000008; pub const CKD_CPDIVERSIFY_KDF: CK_X9_42_DH_KDF_TYPE = 0x00000009; -/// CK_ECDH1_DERIVE_PARAMS provides the parameters to the -/// CKM_ECDH1_DERIVE and CKM_ECDH1_COFACTOR_DERIVE mechanisms, -/// where each party contributes one key pair. cryptoki_aligned! { + /// CK_ECDH1_DERIVE_PARAMS provides the parameters to the + /// CKM_ECDH1_DERIVE and CKM_ECDH1_COFACTOR_DERIVE mechanisms, + /// where each party contributes one key pair. pub struct CK_ECDH1_DERIVE_PARAMS { pub kdf: CK_EC_KDF_TYPE, pub ulSharedDataLen: CK_ULONG, @@ -1621,9 +1626,9 @@ cryptoki_aligned! { pub type CK_ECDH1_DERIVE_PARAMS_PTR = *mut CK_ECDH1_DERIVE_PARAMS; -/// CK_ECDH2_DERIVE_PARAMS provides the parameters to the -/// CKM_ECMQV_DERIVE mechanism, where each party contributes two key pairs. cryptoki_aligned! { + /// CK_ECDH2_DERIVE_PARAMS provides the parameters to the + /// CKM_ECMQV_DERIVE mechanism, where each party contributes two key pairs. #[derive(Debug, Copy)] pub struct CK_ECDH2_DERIVE_PARAMS { pub kdf: CK_EC_KDF_TYPE, @@ -1665,10 +1670,10 @@ pub type CK_ECMQV_DERIVE_PARAMS_PTR = *mut CK_ECMQV_DERIVE_PARAMS; pub type CK_X9_42_DH_KDF_TYPE = CK_ULONG; pub type CK_X9_42_DH_KDF_TYPE_PTR = *mut CK_X9_42_DH_KDF_TYPE; -/// CK_X9_42_DH1_DERIVE_PARAMS provides the parameters to the -/// CKM_X9_42_DH_DERIVE key derivation mechanism, where each party -/// contributes one key pair cryptoki_aligned! { + /// CK_X9_42_DH1_DERIVE_PARAMS provides the parameters to the + /// CKM_X9_42_DH_DERIVE key derivation mechanism, where each party + /// contributes one key pair #[derive(Debug, Copy)] pub struct CK_X9_42_DH1_DERIVE_PARAMS { pub kdf: CK_X9_42_DH_KDF_TYPE, @@ -1682,10 +1687,10 @@ packed_clone!(CK_X9_42_DH1_DERIVE_PARAMS); pub type CK_X9_42_DH1_DERIVE_PARAMS_PTR = *mut CK_X9_42_DH1_DERIVE_PARAMS; -/// CK_X9_42_DH2_DERIVE_PARAMS provides the parameters to the -/// CKM_X9_42_DH_HYBRID_DERIVE and CKM_X9_42_MQV_DERIVE key derivation -/// mechanisms, where each party contributes two key pairs cryptoki_aligned! { + /// CK_X9_42_DH2_DERIVE_PARAMS provides the parameters to the + /// CKM_X9_42_DH_HYBRID_DERIVE and CKM_X9_42_MQV_DERIVE key derivation + /// mechanisms, where each party contributes two key pairs #[derive(Debug, Copy)] pub struct CK_X9_42_DH2_DERIVE_PARAMS { pub kdf: CK_X9_42_DH_KDF_TYPE, @@ -1722,9 +1727,9 @@ packed_clone!(CK_X9_42_MQV_DERIVE_PARAMS); pub type CK_X9_42_MQV_DERIVE_PARAMS_PTR = *mut CK_X9_42_MQV_DERIVE_PARAMS; -/// CK_KEA_DERIVE_PARAMS provides the parameters to the -/// CKM_KEA_DERIVE mechanism cryptoki_aligned! { + /// CK_KEA_DERIVE_PARAMS provides the parameters to the + /// CKM_KEA_DERIVE mechanism #[derive(Debug, Copy)] pub struct CK_KEA_DERIVE_PARAMS { pub isSender: CK_BBOOL, @@ -1746,10 +1751,9 @@ pub type CK_RC2_PARAMS = CK_ULONG; pub type CK_RC2_PARAMS_PTR = *mut CK_RC2_PARAMS; - -/// CK_RC2_CBC_PARAMS provides the parameters to the CKM_RC2_CBC -/// mechanism cryptoki_aligned! { + /// CK_RC2_CBC_PARAMS provides the parameters to the CKM_RC2_CBC + /// mechanism #[derive(Debug, Copy)] pub struct CK_RC2_CBC_PARAMS { /// effective bits (1-1024) @@ -1763,9 +1767,9 @@ packed_clone!(CK_RC2_CBC_PARAMS); pub type CK_RC2_CBC_PARAMS_PTR = *mut CK_RC2_CBC_PARAMS; -/// CK_RC2_MAC_GENERAL_PARAMS provides the parameters for the -/// CKM_RC2_MAC_GENERAL mechanism cryptoki_aligned! { + /// CK_RC2_MAC_GENERAL_PARAMS provides the parameters for the + /// CKM_RC2_MAC_GENERAL mechanism #[derive(Debug, Copy)] pub struct CK_RC2_MAC_GENERAL_PARAMS { /// effective bits (1-1024) @@ -1779,9 +1783,9 @@ packed_clone!(CK_RC2_MAC_GENERAL_PARAMS); pub type CK_RC2_MAC_GENERAL_PARAMS_PTR = *mut CK_RC2_MAC_GENERAL_PARAMS; -/// CK_RC5_PARAMS provides the parameters to the CKM_RC5_ECB and -/// CKM_RC5_MAC mechanisms cryptoki_aligned! { + /// CK_RC5_PARAMS provides the parameters to the CKM_RC5_ECB and + /// CKM_RC5_MAC mechanisms #[derive(Debug, Copy)] pub struct CK_RC5_PARAMS { /// wordsize in bits @@ -1795,9 +1799,9 @@ packed_clone!(CK_RC5_PARAMS); pub type CK_RC5_PARAMS_PTR = *mut CK_RC5_PARAMS; -/// CK_RC5_CBC_PARAMS provides the parameters to the CKM_RC5_CBC -/// mechanism cryptoki_aligned! { + /// CK_RC5_CBC_PARAMS provides the parameters to the CKM_RC5_CBC + /// mechanism #[derive(Debug, Copy)] pub struct CK_RC5_CBC_PARAMS { /// wordsize in bits @@ -1815,9 +1819,9 @@ packed_clone!(CK_RC5_CBC_PARAMS); pub type CK_RC5_CBC_PARAMS_PTR = *mut CK_RC5_CBC_PARAMS; -/// CK_RC5_MAC_GENERAL_PARAMS provides the parameters for the -/// CKM_RC5_MAC_GENERAL mechanism cryptoki_aligned! { + /// CK_RC5_MAC_GENERAL_PARAMS provides the parameters for the + /// CKM_RC5_MAC_GENERAL mechanism #[derive(Debug, Copy)] pub struct CK_RC5_MAC_GENERAL_PARAMS { /// wordsize in bits @@ -1863,9 +1867,9 @@ packed_clone!(CK_AES_CBC_ENCRYPT_DATA_PARAMS); pub type CK_AES_CBC_ENCRYPT_DATA_PARAMS_PTR = *mut CK_AES_CBC_ENCRYPT_DATA_PARAMS; -/// CK_SKIPJACK_PRIVATE_WRAP_PARAMS provides the parameters to the -/// CKM_SKIPJACK_PRIVATE_WRAP mechanism cryptoki_aligned! { + /// CK_SKIPJACK_PRIVATE_WRAP_PARAMS provides the parameters to the + /// CKM_SKIPJACK_PRIVATE_WRAP mechanism #[derive(Debug, Copy)] pub struct CK_SKIPJACK_PRIVATE_WRAP_PARAMS { pub ulPasswordLen: CK_ULONG, @@ -1885,10 +1889,9 @@ packed_clone!(CK_SKIPJACK_PRIVATE_WRAP_PARAMS); pub type CK_SKIPJACK_PRIVATE_WRAP_PARAMS_PTR = *mut CK_SKIPJACK_PRIVATE_WRAP_PARAMS; - -/// CK_SKIPJACK_RELAYX_PARAMS provides the parameters to the -/// CKM_SKIPJACK_RELAYX mechanism cryptoki_aligned! { + /// CK_SKIPJACK_RELAYX_PARAMS provides the parameters to the + /// CKM_SKIPJACK_RELAYX mechanism #[derive(Debug, Copy)] pub struct CK_SKIPJACK_RELAYX_PARAMS { pub ulOldWrappedXLen: CK_ULONG, @@ -1926,10 +1929,9 @@ packed_clone!(CK_PBE_PARAMS); pub type CK_PBE_PARAMS_PTR = *mut CK_PBE_PARAMS; - -/// CK_KEY_WRAP_SET_OAEP_PARAMS provides the parameters to the -/// CKM_KEY_WRAP_SET_OAEP mechanism cryptoki_aligned! { + /// CK_KEY_WRAP_SET_OAEP_PARAMS provides the parameters to the + /// CKM_KEY_WRAP_SET_OAEP mechanism #[derive(Debug, Copy)] pub struct CK_KEY_WRAP_SET_OAEP_PARAMS { /// block contents byte @@ -2144,9 +2146,9 @@ pub type CK_PKCS5_PBKDF2_SALT_SOURCE_TYPE_PTR = *mut CK_PKCS5_PBKDF2_SALT_SOURCE /// The following salt value sources are defined in PKCS #5 v2.0. pub const CKZ_SALT_SPECIFIED: CK_PKCS5_PBKDF2_SALT_SOURCE_TYPE = 0x00000001; -/// CK_PKCS5_PBKD2_PARAMS is a structure that provides the -/// parameters to the CKM_PKCS5_PBKD2 mechanism. cryptoki_aligned! { + /// CK_PKCS5_PBKD2_PARAMS is a structure that provides the + /// parameters to the CKM_PKCS5_PBKD2 mechanism. #[derive(Debug, Copy)] pub struct CK_PKCS5_PBKD2_PARAMS { pub saltSource: CK_PKCS5_PBKDF2_SALT_SOURCE_TYPE, @@ -2164,10 +2166,10 @@ packed_clone!(CK_PKCS5_PBKD2_PARAMS); pub type CK_PKCS5_PBKD2_PARAMS_PTR = *mut CK_PKCS5_PBKD2_PARAMS; -/// CK_PKCS5_PBKD2_PARAMS2 is a corrected version of the CK_PKCS5_PBKD2_PARAMS -/// structure that provides the parameters to the CKM_PKCS5_PBKD2 mechanism -/// noting that the ulPasswordLen field is a CK_ULONG and not a CK_ULONG_PTR. cryptoki_aligned! { + /// CK_PKCS5_PBKD2_PARAMS2 is a corrected version of the CK_PKCS5_PBKD2_PARAMS + /// structure that provides the parameters to the CKM_PKCS5_PBKD2 mechanism + /// noting that the ulPasswordLen field is a CK_ULONG and not a CK_ULONG_PTR. #[derive(Debug, Copy)] pub struct CK_PKCS5_PBKD2_PARAMS2 { pub saltSource: CK_PKCS5_PBKDF2_SALT_SOURCE_TYPE, @@ -2293,8 +2295,8 @@ packed_clone!(CK_CCM_PARAMS); pub type CK_CCM_PARAMS_PTR = *mut CK_CCM_PARAMS; -/// Deprecated. Use CK_GCM_PARAMS cryptoki_aligned! { + /// Deprecated. Use CK_GCM_PARAMS #[derive(Debug, Copy)] pub struct CK_AES_GCM_PARAMS { pub pIv: CK_BYTE_PTR, @@ -2309,8 +2311,8 @@ packed_clone!(CK_AES_GCM_PARAMS); pub type CK_AES_GCM_PARAMS_PTR = *mut CK_AES_GCM_PARAMS; -/// Deprecated. Use CK_CCM_PARAMS cryptoki_aligned! { + /// Deprecated. Use CK_CCM_PARAMS #[derive(Debug, Copy)] pub struct CK_AES_CCM_PARAMS { pub ulDataLen: CK_ULONG,