Skip to content

Commit

Permalink
update the capi feature handling (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal authored Feb 22, 2025
1 parent 1858882 commit 7c7da6c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 37 deletions.
13 changes: 9 additions & 4 deletions biscuit-capi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ documentation = "https://docs.rs/biscuit-auth"
homepage = "https://github.com/biscuit-auth/biscuit"
repository = "https://github.com/biscuit-auth/biscuit-rust"

[features]
capi = []

[dependencies]
biscuit-auth = { version = "6.0.0-beta.2", path = "../biscuit-auth", features = [
"datalog-macro",
"serde-error",
"pem",
] }
libc = { version = "0.2", optional = true }
libc = "0.2"
rand = "0.8"

[features]
capi = ["libc"]

[dev-dependencies]
inline-c = "0.1"

Expand All @@ -31,3 +31,8 @@ name = "biscuit_auth"

[package.metadata.capi.header]
name = "biscuit_auth"

[[test]]
name = "capi"
required-features = ["capi"]
path = "tests/capi.rs"
4 changes: 2 additions & 2 deletions biscuit-capi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This crate provides a C API for the Biscuit token library. It is a wrapper aroun
To build the C API, you need to have the Rust toolchain installed. You can then build the C API by running:

```sh
cargo cinstall --release --features="capi" --prefix=/path/to/install --destdir=/path/to/destdir
cargo cinstall --release --prefix=/path/to/install --destdir=/path/to/destdir
```
It will produce a shared library in the `--destdir` directory and also the C headers.
You can then link against the generated library in your C code.
Expand All @@ -21,7 +21,7 @@ Currently, only Linux x86_64 and MacOS (arm) are provided.
### Running the tests

```sh
cargo ctest --features="capi"
cargo ctest
```

## License
Expand Down
58 changes: 27 additions & 31 deletions biscuit-capi/tests/capi.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
//#[cfg(test)]
#[cfg(feature = "capi")]
mod capi {
use inline_c::assert_c;

#[test]
fn build() {
(assert_c! {
use inline_c::assert_c;

#[test]
fn build() {
(assert_c! {
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
Expand Down Expand Up @@ -147,33 +144,32 @@ biscuit block count: 2
biscuit block 0 context: (null)
"#,
);
}
}

#[test]
fn serialize_keys() {
(assert_c! {
#include <stdio.h>
#include <string.h>
#include "biscuit_auth.h"
#[test]
fn serialize_keys() {
(assert_c! {
#include <stdio.h>
#include <string.h>
#include "biscuit_auth.h"

int main() {
char *seed = "abcdefghabcdefghabcdefghabcdefgh";
uint8_t * priv_buf = malloc(32);
uint8_t * pub_buf = malloc(32);
int main() {
char *seed = "abcdefghabcdefghabcdefghabcdefgh";
uint8_t * priv_buf = malloc(32);
uint8_t * pub_buf = malloc(32);


KeyPair * kp = key_pair_new((const uint8_t *) seed, strlen(seed), 0);
printf("key_pair creation error? %s\n", error_message());
PublicKey* pubkey = key_pair_public(kp);
KeyPair * kp = key_pair_new((const uint8_t *) seed, strlen(seed), 0);
printf("key_pair creation error? %s\n", error_message());
PublicKey* pubkey = key_pair_public(kp);

key_pair_serialize(kp, priv_buf);
public_key_serialize(pubkey, pub_buf);
key_pair_serialize(kp, priv_buf);
public_key_serialize(pubkey, pub_buf);

public_key_free(pubkey);
key_pair_free(kp);
}
})
.success()
.stdout("key_pair creation error? (null)\n");
}
public_key_free(pubkey);
key_pair_free(kp);
}
})
.success()
.stdout("key_pair creation error? (null)\n");
}

0 comments on commit 7c7da6c

Please sign in to comment.