Struct biscuit_auth::Biscuit
source · [−]pub struct Biscuit { /* private fields */ }Expand description
This structure represents a valid Biscuit token
It contains multiple Block elements, the associated symbol table,
and a serialized version of this data
extern crate biscuit_auth as biscuit;
use biscuit::{KeyPair, Biscuit, builder::*};
fn main() {
let root = KeyPair::new();
// first we define the authority block for global data,
// like access rights
// data from the authority block cannot be created in any other block
let mut builder = Biscuit::builder(&root);
builder.add_authority_fact(fact("right", &[string("/a/file1.txt"), s("read")]));
// facts and rules can also be parsed from a string
builder.add_authority_fact("right(\"/a/file1.txt\", \"read\")").expect("parse error");
let token1 = builder.build().unwrap();
// we can create a new block builder from that token
let mut builder2 = token1.create_block();
builder2.check_operation("read");
let token2 = token1.append(builder2).unwrap();
}Implementations
sourceimpl Biscuit
impl Biscuit
sourcepub fn builder(root: &KeyPair) -> BiscuitBuilder<'_>
pub fn builder(root: &KeyPair) -> BiscuitBuilder<'_>
create the first block’s builder
call builder::BiscuitBuilder::build to create the token
sourcepub fn from<T, F>(slice: T, f: F) -> Result<Self, Token> where
F: Fn(Option<u32>) -> PublicKey,
T: AsRef<[u8]>,
pub fn from<T, F>(slice: T, f: F) -> Result<Self, Token> where
F: Fn(Option<u32>) -> PublicKey,
T: AsRef<[u8]>,
deserializes a token and validates the signature using the root public key
sourcepub fn from_base64<T, F>(slice: T, f: F) -> Result<Self, Token> where
F: Fn(Option<u32>) -> PublicKey,
T: AsRef<[u8]>,
pub fn from_base64<T, F>(slice: T, f: F) -> Result<Self, Token> where
F: Fn(Option<u32>) -> PublicKey,
T: AsRef<[u8]>,
deserializes a token and validates the signature using the root public key
sourcepub fn to_base64(&self) -> Result<String, Token>
pub fn to_base64(&self) -> Result<String, Token>
serializes the token and encode it to a (URL safe) base64 string
sourcepub fn serialized_size(&self) -> Result<usize, Token>
pub fn serialized_size(&self) -> Result<usize, Token>
serializes the token
sourcepub fn seal(&self) -> Result<Biscuit, Token>
pub fn seal(&self) -> Result<Biscuit, Token>
creates a sealed version of the token
sealed tokens cannot be attenuated
creates a authorizer from this token
sourcepub fn create_block(&self) -> BlockBuilder
pub fn create_block(&self) -> BlockBuilder
creates a new block builder
sourcepub fn append(&self, block_builder: BlockBuilder) -> Result<Self, Token>
pub fn append(&self, block_builder: BlockBuilder) -> Result<Self, Token>
adds a new block to the token
since the public key is integrated into the token, the keypair can be discarded right after calling this function
sourcepub fn context(&self) -> Vec<Option<String>>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn context(&self) -> Vec<Option<String>>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
returns the list of context elements of each block
the context is a free form text field in which application specific data can be stored
sourcepub fn revocation_identifiers(&self) -> Vec<Vec<u8>>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn revocation_identifiers(&self) -> Vec<Vec<u8>>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
returns a list of revocation identifiers for each block, in order
if a token is generated with the same keys and the same content, those identifiers will stay the same
sourcepub fn print_block_source(&self, index: usize) -> Option<String>
pub fn print_block_source(&self, index: usize) -> Option<String>
prints the content of a block as Datalog source code
sourcepub fn container(&self) -> Option<&SerializedBiscuit>
pub fn container(&self) -> Option<&SerializedBiscuit>
returns the internal representation of the token
sourcepub fn append_with_keypair(
&self,
keypair: &KeyPair,
block_builder: BlockBuilder
) -> Result<Self, Token>
pub fn append_with_keypair(
&self,
keypair: &KeyPair,
block_builder: BlockBuilder
) -> Result<Self, Token>
adds a new block to the token, using the provided CSPRNG
since the public key is integrated into the token, the keypair can be discarded right after calling this function
sourcepub fn block_symbols(&self, index: usize) -> Option<Vec<String>>
pub fn block_symbols(&self, index: usize) -> Option<Vec<String>>
gets the list of symbols from a block
sourcepub fn block_count(&self) -> usize
pub fn block_count(&self) -> usize
returns the number of blocks (at least 1)
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Biscuit
impl Send for Biscuit
impl Sync for Biscuit
impl Unpin for Biscuit
impl UnwindSafe for Biscuit
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more