Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump bindgen for version 0.2.x of crate #82

Merged
merged 6 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ jobs:
rustup target add aarch64-unknown-linux-gnu &&
rustup target add i686-unknown-linux-gnu &&
rustup target add powerpc64-unknown-linux-gnu &&
rustup target add powerpc64le-unknown-linux-gnu
rustup target add powerpc64le-unknown-linux-gnu &&
rustup target add x86_64-apple-darwin &&
rustup target add aarch64-apple-darwin

- name: Test script
env:
Expand Down
2 changes: 2 additions & 0 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ RUST_BACKTRACE=1 cargo build --target aarch64-unknown-linux-gnu
RUST_BACKTRACE=1 cargo build --target i686-unknown-linux-gnu
RUST_BACKTRACE=1 cargo build --target powerpc64-unknown-linux-gnu
RUST_BACKTRACE=1 cargo build --target powerpc64le-unknown-linux-gnu
RUST_BACKTRACE=1 cargo build --target x86_64-apple-darwin
RUST_BACKTRACE=1 cargo build --target aarch64-apple-darwin

pushd cryptoki-sys
RUST_BACKTRACE=1 cargo build --features generate-bindings
Expand Down
2 changes: 1 addition & 1 deletion cryptoki-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repository = "https://github.com/parallaxsecond/rust-cryptoki"
documentation = "https://docs.rs/crate/cryptoki"

[build-dependencies]
bindgen = { version = "0.57.0", optional = true }
bindgen = { version = "0.59.1", optional = true }
target-lexicon = "0.12.0"

[dependencies]
Expand Down
7 changes: 4 additions & 3 deletions cryptoki-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fn main() {
(Architecture::Powerpc64, OperatingSystem::Linux) => {}
(Architecture::Powerpc64le, OperatingSystem::Linux) => {}
(Architecture::X86_64, OperatingSystem::Darwin) => {}
(Architecture::Aarch64(_), OperatingSystem::Darwin) => {}
(arch, os) => {
panic!("Compilation target (architecture, OS) tuple ({}, {}) is not part of the supported tuples. Please compile with the \"generate-bindings\" feature or add support for your platform :)", arch, os);
}
Expand All @@ -37,12 +38,12 @@ fn generate_bindings() {
// The PKCS11 library works in a slightly different way to most shared libraries. We have
// to call `C_GetFunctionList`, which returns a list of pointers to the _actual_ library
// functions. This is the only function we need to create a binding for.
.whitelist_function("C_GetFunctionList")
.allowlist_function("C_GetFunctionList")
// This is needed because no types will be generated if `whitelist_function` is used.
// Unsure if this is a bug.
.whitelist_type("*")
.allowlist_type("*")
// See this issue: https://github.com/parallaxsecond/rust-cryptoki/issues/12
.blacklist_type("max_align_t")
.blocklist_type("max_align_t")
// Derive the `Debug` trait for the generated structs where possible.
.derive_debug(true)
// Derive the `Default` trait for the generated structs where possible.
Expand Down
25 changes: 25 additions & 0 deletions cryptoki-sys/regenerate_bindings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

# Copyright 2022 Contributors to the Parsec project.
# SPDX-License-Identifier: Apache-2.0

set -xeuf -o pipefail

targets="aarch64-unknown-linux-gnu arm-unknown-linux-gnueabi i686-unknown-linux-gnu powerpc64-unknown-linux-gnu x86_64-unknown-linux-gnu x86_64-apple-darwin aarch64-apple-darwin"
TARGET_INSTALLED=

for target in $targets; do

# Check if the target is already installed
if ! rustup target list | grep -q "$target (installed)"; then
rustup target install $target
TARGET_INSTALLED="$target"
fi

cargo build --target $target --features generate-bindings
find ../target/$target/ -name pkcs11_bindings.rs | xargs -I '{}' cp '{}' src/bindings/$target.rs

if [ "$TARGET_INSTALLED" == "$target" ]; then
rustup target remove $target
fi
done
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* automatically generated by rust-bindgen 0.57.0 */
/* automatically generated by rust-bindgen 0.59.2 */

pub type CK_FLAGS = ::std::os::raw::c_ulong;
#[repr(C)]
Expand Down Expand Up @@ -115,7 +115,7 @@ fn bindgen_test_layout__CK_INFO() {
pub type CK_NOTIFICATION = ::std::os::raw::c_ulong;
pub type CK_SLOT_ID = ::std::os::raw::c_ulong;
#[repr(C)]
#[derive(Copy, Clone)]
#[derive(Debug, Copy, Clone)]
pub struct _CK_SLOT_INFO {
pub slotDescription: [::std::os::raw::c_uchar; 64usize],
pub manufacturerID: [::std::os::raw::c_uchar; 32usize],
Expand Down Expand Up @@ -188,7 +188,11 @@ fn bindgen_test_layout__CK_SLOT_INFO() {
}
impl Default for _CK_SLOT_INFO {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
Expand Down Expand Up @@ -540,7 +544,11 @@ fn bindgen_test_layout__CK_ATTRIBUTE() {
}
impl Default for _CK_ATTRIBUTE {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
Expand Down Expand Up @@ -646,7 +654,11 @@ fn bindgen_test_layout__CK_MECHANISM() {
}
impl Default for _CK_MECHANISM {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
Expand Down Expand Up @@ -752,7 +764,11 @@ fn bindgen_test_layout_CK_OTP_PARAM() {
}
impl Default for CK_OTP_PARAM {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
Expand Down Expand Up @@ -796,7 +812,11 @@ fn bindgen_test_layout_CK_OTP_PARAMS() {
}
impl Default for CK_OTP_PARAMS {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
Expand Down Expand Up @@ -840,7 +860,11 @@ fn bindgen_test_layout_CK_OTP_SIGNATURE_INFO() {
}
impl Default for CK_OTP_SIGNATURE_INFO {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
pub type CK_RSA_PKCS_MGF_TYPE = ::std::os::raw::c_ulong;
Expand Down Expand Up @@ -973,7 +997,11 @@ fn bindgen_test_layout_ck_rsa_pkcs_oaep_params() {
}
impl Default for ck_rsa_pkcs_oaep_params {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
Expand Down Expand Up @@ -1100,7 +1128,11 @@ fn bindgen_test_layout_ck_gcm_params() {
}
impl Default for ck_gcm_params {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
pub type ck_ec_kdf_t = ::std::os::raw::c_ulong;
Expand Down Expand Up @@ -1186,7 +1218,11 @@ fn bindgen_test_layout_ck_ecdh1_derive_params() {
}
impl Default for ck_ecdh1_derive_params {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
Expand Down Expand Up @@ -1234,7 +1270,11 @@ fn bindgen_test_layout_ck_key_derivation_string_data() {
}
impl Default for ck_key_derivation_string_data {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
Expand Down Expand Up @@ -1295,7 +1335,11 @@ fn bindgen_test_layout_ck_des_cbc_encrypt_data_params() {
}
impl Default for ck_des_cbc_encrypt_data_params {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
#[repr(C)]
Expand Down Expand Up @@ -1356,7 +1400,11 @@ fn bindgen_test_layout_ck_aes_cbc_encrypt_data_params() {
}
impl Default for ck_aes_cbc_encrypt_data_params {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
pub type CK_RV = ::std::os::raw::c_ulong;
Expand Down Expand Up @@ -2770,7 +2818,11 @@ fn bindgen_test_layout__CK_C_INITIALIZE_ARGS() {
}
impl Default for _CK_C_INITIALIZE_ARGS {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
unsafe {
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
s.assume_init()
}
}
}
pub type size_t = ::std::os::raw::c_ulong;
Expand Down Expand Up @@ -2851,18 +2903,24 @@ impl Pkcs11 {
where
P: AsRef<::std::ffi::OsStr>,
{
let __library = ::libloading::Library::new(path)?;
let library = ::libloading::Library::new(path)?;
Self::from_library(library)
}
pub unsafe fn from_library<L>(library: L) -> Result<Self, ::libloading::Error>
where
L: Into<::libloading::Library>,
{
let __library = library.into();
let C_GetFunctionList = __library.get(b"C_GetFunctionList\0").map(|sym| *sym);
Ok(Pkcs11 {
__library,
C_GetFunctionList,
})
}
pub unsafe fn C_GetFunctionList(&self, function_list: *mut *mut _CK_FUNCTION_LIST) -> CK_RV {
let sym = self
(self
.C_GetFunctionList
.as_ref()
.expect("Expected function, got error.");
(sym)(function_list)
.expect("Expected function, got error."))(function_list)
}
}
Loading