Skip to content

Commit

Permalink
update imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal committed Mar 26, 2024
1 parent 49fef7f commit 5202d94
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[workspace]
members = ["biscuit-auth", "biscuit-quote", "biscuit-parser"]
members = ["biscuit-auth", "biscuit-quote", "biscuit-parser", "biscuit-capi"]
3 changes: 0 additions & 3 deletions biscuit-auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ repository = "https://github.com/biscuit-auth/biscuit-rust"
[features]
default = ["regex-full", "datalog-macro"]
regex-full = [ "regex/perf", "regex/unicode"]
# used by cargo-c to signal the compilation of C bindings
capi = ["inline-c"]
wasm = ["wasm-bindgen", "getrandom/wasm-bindgen"]
# used by biscuit-wasm to serialize errors to JSON
serde-error = ["serde", "biscuit-parser/serde-error"]
Expand All @@ -38,7 +36,6 @@ hex = "0.4"
zeroize = { version = "1", default-features = false }
thiserror = "1"
rand = { version = "0.8" }
inline-c = { version = "0.1", optional = true }
wasm-bindgen = { version = "0.2", optional = true }
base64 = "0.13.0"
ed25519-dalek = { version = "2.0.0", features = ["rand_core", "zeroize"] }
Expand Down
7 changes: 6 additions & 1 deletion biscuit-capi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ name = "biscuit-capi"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
# used by cargo-c to signal the compilation of C bindings
capi = ["inline-c"]

[dependencies]
biscuit-auth = { version = "4.1.1", path = "../biscuit-auth" }
inline-c = { version = "0.1", optional = true }
rand = { version = "0.8" }

48 changes: 24 additions & 24 deletions biscuit-capi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use std::{
os::raw::c_char,
};

use crate::datalog::SymbolTable;
use biscuit_auth::datalog::SymbolTable;

enum Error {
Biscuit(crate::error::Token),
Biscuit(biscuit_auth::error::Token),
InvalidArgument,
}

Expand All @@ -22,8 +22,8 @@ impl fmt::Display for Error {
}
}

impl From<crate::error::Token> for Error {
fn from(error: crate::error::Token) -> Self {
impl From<biscuit_auth::error::Token> for Error {
fn from(error: biscuit_auth::error::Token) -> Self {
Error::Biscuit(error)
}
}
Expand Down Expand Up @@ -105,7 +105,7 @@ pub extern "C" fn error_kind() -> ErrorKind {
Some(ref err) => match err {
Error::InvalidArgument => ErrorKind::InvalidArgument,
Error::Biscuit(e) => {
use crate::error::*;
use biscuit_auth::error::*;
match e {
Token::InternalError => ErrorKind::InternalError,
Token::Format(Format::Signature(Signature::InvalidFormat)) => {
Expand Down Expand Up @@ -186,7 +186,7 @@ pub extern "C" fn error_kind() -> ErrorKind {

#[no_mangle]
pub extern "C" fn error_check_count() -> u64 {
use crate::error::*;
use biscuit_auth::error::*;
LAST_ERROR.with(|prev| match *prev.borrow() {
Some(Error::Biscuit(Token::FailedLogic(Logic::Unauthorized { ref checks, .. })))
| Some(Error::Biscuit(Token::FailedLogic(Logic::NoMatchingPolicy { ref checks }))) => {
Expand All @@ -198,7 +198,7 @@ pub extern "C" fn error_check_count() -> u64 {

#[no_mangle]
pub extern "C" fn error_check_id(check_index: u64) -> u64 {
use crate::error::*;
use biscuit_auth::error::*;
LAST_ERROR.with(|prev| match *prev.borrow() {
Some(Error::Biscuit(Token::FailedLogic(Logic::Unauthorized { ref checks, .. })))
| Some(Error::Biscuit(Token::FailedLogic(Logic::NoMatchingPolicy { ref checks }))) => {
Expand All @@ -219,7 +219,7 @@ pub extern "C" fn error_check_id(check_index: u64) -> u64 {

#[no_mangle]
pub extern "C" fn error_check_block_id(check_index: u64) -> u64 {
use crate::error::*;
use biscuit_auth::error::*;
LAST_ERROR.with(|prev| match *prev.borrow() {
Some(Error::Biscuit(Token::FailedLogic(Logic::Unauthorized { ref checks, .. })))
| Some(Error::Biscuit(Token::FailedLogic(Logic::NoMatchingPolicy { ref checks }))) => {
Expand All @@ -240,7 +240,7 @@ pub extern "C" fn error_check_block_id(check_index: u64) -> u64 {
/// the string is overwritten on each call
#[no_mangle]
pub extern "C" fn error_check_rule(check_index: u64) -> *const c_char {
use crate::error::*;
use biscuit_auth::error::*;
thread_local! {
static CAVEAT_RULE: RefCell<Option<CString>> = RefCell::new(None);
}
Expand Down Expand Up @@ -271,7 +271,7 @@ pub extern "C" fn error_check_rule(check_index: u64) -> *const c_char {

#[no_mangle]
pub extern "C" fn error_check_is_authorizer(check_index: u64) -> bool {
use crate::error::*;
use biscuit_auth::error::*;
LAST_ERROR.with(|prev| match *prev.borrow() {
Some(Error::Biscuit(Token::FailedLogic(Logic::Unauthorized { ref checks, .. })))
| Some(Error::Biscuit(Token::FailedLogic(Logic::NoMatchingPolicy { ref checks }))) => {
Expand All @@ -288,12 +288,12 @@ pub extern "C" fn error_check_is_authorizer(check_index: u64) -> bool {
})
}

pub struct Biscuit(crate::token::Biscuit);
pub struct KeyPair(crate::crypto::KeyPair);
pub struct PublicKey(crate::crypto::PublicKey);
pub struct BiscuitBuilder(crate::token::builder::BiscuitBuilder);
pub struct BlockBuilder(crate::token::builder::BlockBuilder);
pub struct Authorizer(crate::token::authorizer::Authorizer);
pub struct Biscuit(biscuit_auth::Biscuit);
pub struct KeyPair(biscuit_auth::KeyPair);
pub struct PublicKey(biscuit_auth::PublicKey);
pub struct BiscuitBuilder(biscuit_auth::builder::BiscuitBuilder);
pub struct BlockBuilder(biscuit_auth::builder::BlockBuilder);
pub struct Authorizer(biscuit_auth::Authorizer);

#[no_mangle]
pub unsafe extern "C" fn key_pair_new<'a>(
Expand All @@ -311,7 +311,7 @@ pub unsafe extern "C" fn key_pair_new<'a>(

let mut rng: StdRng = SeedableRng::from_seed(seed);

Some(Box::new(KeyPair(crate::crypto::KeyPair::new_with_rng(
Some(Box::new(KeyPair(biscuit_auth::KeyPair::new_with_rng(
&mut rng,
))))
}
Expand Down Expand Up @@ -346,12 +346,12 @@ pub unsafe extern "C" fn key_pair_serialize(kp: Option<&KeyPair>, buffer_ptr: *m
pub unsafe extern "C" fn key_pair_deserialize(buffer_ptr: *mut u8) -> Option<Box<KeyPair>> {
let input_slice = std::slice::from_raw_parts_mut(buffer_ptr, 32);

match crate::crypto::PrivateKey::from_bytes(input_slice).ok() {
match biscuit_auth::PrivateKey::from_bytes(input_slice).ok() {
None => {
update_last_error(Error::InvalidArgument);
None
}
Some(privkey) => Some(Box::new(KeyPair(crate::crypto::KeyPair::from(&privkey)))),
Some(privkey) => Some(Box::new(KeyPair(biscuit_auth::KeyPair::from(&privkey)))),
}
}

Expand Down Expand Up @@ -381,7 +381,7 @@ pub unsafe extern "C" fn public_key_serialize(
pub unsafe extern "C" fn public_key_deserialize(buffer_ptr: *mut u8) -> Option<Box<PublicKey>> {
let input_slice = std::slice::from_raw_parts_mut(buffer_ptr, 32);

match crate::crypto::PublicKey::from_bytes(input_slice).ok() {
match biscuit_auth::PublicKey::from_bytes(input_slice).ok() {
None => {
update_last_error(Error::InvalidArgument);
None
Expand All @@ -395,7 +395,7 @@ pub unsafe extern "C" fn public_key_free(_kp: Option<Box<PublicKey>>) {}

#[no_mangle]
pub unsafe extern "C" fn biscuit_builder() -> Option<Box<BiscuitBuilder>> {
Some(Box::new(BiscuitBuilder(crate::token::Biscuit::builder())))
Some(Box::new(BiscuitBuilder(biscuit_auth::Biscuit::builder())))
}

#[no_mangle]
Expand Down Expand Up @@ -569,7 +569,7 @@ pub unsafe extern "C" fn biscuit_from<'a>(
}
let root = root?;

crate::token::Biscuit::from(biscuit, root.0)
biscuit_auth::Biscuit::from(biscuit, root.0)
.map(Biscuit)
.map(Box::new)
.ok()
Expand Down Expand Up @@ -695,7 +695,7 @@ pub unsafe extern "C" fn biscuit_block_count(biscuit: Option<&Biscuit>) -> usize

let biscuit = biscuit.unwrap();

biscuit.0.blocks.len() + 1
biscuit.0.block_count()
}

#[no_mangle]
Expand Down Expand Up @@ -915,7 +915,7 @@ pub unsafe extern "C" fn biscuit_block_context(

#[no_mangle]
pub unsafe extern "C" fn create_block() -> Box<BlockBuilder> {
Box::new(BlockBuilder(crate::token::builder::BlockBuilder::new()))
Box::new(BlockBuilder(biscuit_auth::builder::BlockBuilder::new()))
}

#[no_mangle]
Expand Down
File renamed without changes.

0 comments on commit 5202d94

Please sign in to comment.