Skip to content

Commit

Permalink
Prefer getting C types from libc instead of std::os::raw
Browse files Browse the repository at this point in the history
This allows botan-sys to be no_std by default.

The wrapper crate relies on Vec, String, CString and may prove
difficult to convert to no_std, not really sure.

See #10
  • Loading branch information
randombit committed Nov 17, 2018
1 parent 56473aa commit bb91860
Show file tree
Hide file tree
Showing 22 changed files with 27 additions and 18 deletions.
2 changes: 2 additions & 0 deletions botan-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ travis-ci = { repository = "randombit/botan-rs" }
status = "actively-developed"

[dependencies]
# we don't need std support
libc = { version = "0.2", default-features = false }
2 changes: 1 addition & 1 deletion botan-sys/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::os::raw::{c_int, c_char};
use libc::{c_int, c_char};

pub enum botan_block_cipher_struct {}
pub type botan_block_cipher_t = *mut botan_block_cipher_struct;
Expand Down
2 changes: 1 addition & 1 deletion botan-sys/src/cipher.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::os::raw::{c_int, c_char};
use libc::{c_int, c_char};

pub enum botan_cipher_struct {}
pub type botan_cipher_t = *mut botan_cipher_struct;
Expand Down
2 changes: 1 addition & 1 deletion botan-sys/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::os::raw::{c_int, c_char};
use libc::{c_int, c_char};

pub type BOTAN_FFI_ERROR = c_int;

Expand Down
2 changes: 1 addition & 1 deletion botan-sys/src/fpe.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::os::raw::{c_int};
use libc::{c_int};

use mp::botan_mp_t;

Expand Down
2 changes: 1 addition & 1 deletion botan-sys/src/hash.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::os::raw::{c_int, c_char};
use libc::{c_int, c_char};

pub enum botan_hash_struct {}
pub type botan_hash_t = *mut botan_hash_struct;
Expand Down
2 changes: 1 addition & 1 deletion botan-sys/src/kdf.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::os::raw::{c_int, c_char};
use libc::{c_int, c_char};

extern "C" {

Expand Down
2 changes: 1 addition & 1 deletion botan-sys/src/keywrap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::os::raw::{c_int};
use libc::{c_int};

extern "C" {

Expand Down
4 changes: 4 additions & 0 deletions botan-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#![deny(warnings)]
#![allow(non_camel_case_types)]

#![no_std]

extern crate libc;

mod block;
mod cipher;
mod errors;
Expand Down
2 changes: 1 addition & 1 deletion botan-sys/src/mac.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::os::raw::{c_int, c_char};
use libc::{c_int, c_char};

pub enum botan_mac_struct {}
pub type botan_mac_t = *mut botan_mac_struct;
Expand Down
2 changes: 1 addition & 1 deletion botan-sys/src/mp.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::os::raw::{c_int, c_char};
use libc::{c_int, c_char};

use rng::botan_rng_t;

Expand Down
2 changes: 1 addition & 1 deletion botan-sys/src/otp.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::os::raw::{c_int, c_char};
use libc::{c_int, c_char};

pub enum botan_hotp_struct {}
pub type botan_hotp_t = *mut botan_hotp_struct;
Expand Down
2 changes: 1 addition & 1 deletion botan-sys/src/passhash.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::os::raw::{c_int, c_char};
use libc::{c_int, c_char};

use rng::botan_rng_t;

Expand Down
2 changes: 1 addition & 1 deletion botan-sys/src/pk_ops.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::os::raw::{c_int, c_char};
use libc::{c_int, c_char};

use rng::botan_rng_t;
use pubkey::{botan_pubkey_t, botan_privkey_t};
Expand Down
2 changes: 1 addition & 1 deletion botan-sys/src/pubkey.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::os::raw::{c_int, c_char};
use libc::{c_int, c_char};

use mp::botan_mp_t;
use rng::botan_rng_t;
Expand Down
2 changes: 1 addition & 1 deletion botan-sys/src/rng.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::os::raw::{c_int, c_char};
use libc::{c_int, c_char};

pub enum botan_rng_struct {}
pub type botan_rng_t = *mut botan_rng_struct;
Expand Down
2 changes: 1 addition & 1 deletion botan-sys/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::os::raw::{c_int, c_char, c_void};
use libc::{c_int, c_char, c_void};

extern "C" {

Expand Down
2 changes: 1 addition & 1 deletion botan-sys/src/version.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::os::raw::{c_int, c_char};
use libc::{c_int, c_char};

extern "C" {

Expand Down
2 changes: 1 addition & 1 deletion botan-sys/src/x509.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::os::raw::{c_int, c_char, c_uint};
use libc::{c_int, c_char, c_uint};

use pubkey::{botan_pubkey_t, botan_privkey_t};
use rng::botan_rng_t;
Expand Down
2 changes: 2 additions & 0 deletions botan/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ status = "actively-developed"

[dependencies]
botan-sys = { version = "0.4.0", path = "../botan-sys" }
# we don't need std support
libc = { version = "0.2", default-features = false }
1 change: 1 addition & 0 deletions botan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//! A wrapper for the Botan cryptography library

extern crate botan_sys;
extern crate libc;

macro_rules! call_botan {
($x:expr) => {
Expand Down
2 changes: 1 addition & 1 deletion botan/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use botan_sys::*;

pub(crate) use std::os::raw::{c_char, c_int, c_void};
pub(crate) use libc::{c_char, c_int, c_void};
pub(crate) use std::ffi::{CStr, CString};
pub(crate) use std::ptr;
pub(crate) use std::mem;
Expand Down

0 comments on commit bb91860

Please sign in to comment.