Enum TokenError

Source
pub enum TokenError {
    BiscuitError(String),
    VerificationError(String),
    InvalidKeyFormat(String),
    AuthorizationError(String),
    Generic(String),
}
Expand description

Error type for hessra-token operations

Variants§

§

BiscuitError(String)

Error occurred during Biscuit token operations

§

VerificationError(String)

Error occurred during token verification

§

InvalidKeyFormat(String)

Invalid key format provided

§

AuthorizationError(String)

Token authorization failed

§

Generic(String)

Generic error with message

Implementations§

Source§

impl TokenError

Source

pub fn biscuit_error<E: StdError>(err: E) -> Self

Create a new Biscuit-related error

Examples found in repository?
examples/token_verification.rs (line 105)
92fn generate_example_token(keypair: Arc<KeyPair>) -> Result<String, TokenError> {
93    // Create a simple test biscuit with authorization rules
94    let biscuit_builder = biscuit!(
95        r#"
96            // Grant rights to alice for resource1
97            right("alice", "resource1", "read");
98            right("alice", "resource1", "write");
99        "#
100    );
101
102    // Build and serialize the token
103    let biscuit = biscuit_builder
104        .build(&keypair)
105        .map_err(|e| TokenError::biscuit_error(e))?;
106
107    let token_bytes = biscuit.to_vec().map_err(|e| TokenError::biscuit_error(e))?;
108
109    // Encode to base64 for transmission
110    Ok(encode_token(&token_bytes))
111}
112
113/// Generate a token with service chain attestations
114fn generate_service_chain_token(
115    root_keypair: Arc<KeyPair>,
116    service1_public_key: String,
117    service2_public_key: String,
118) -> Result<String, TokenError> {
119    // Create a biscuit with service chain authorization
120    let biscuit_builder = biscuit!(
121        r#"
122            // Basic rights
123            right("alice", "resource1", "read");
124            right("alice", "resource1", "write");
125            
126            // Service nodes
127            node($s, "node1") <- service($s) trusting authority, {node1_public_key};
128            node($s, "node2") <- service($s) trusting authority, {node2_public_key};
129        "#,
130        node1_public_key = biscuit_key_from_string(service1_public_key)?,
131        node2_public_key = biscuit_key_from_string(service2_public_key)?,
132    );
133
134    // Build and serialize the token
135    let biscuit = biscuit_builder
136        .build(&root_keypair)
137        .map_err(|e| TokenError::biscuit_error(e))?;
138
139    let token_bytes = biscuit.to_vec().map_err(|e| TokenError::biscuit_error(e))?;
140
141    // Encode to base64
142    Ok(encode_token(&token_bytes))
143}
More examples
Hide additional examples
examples/token_attenuation.rs (line 75)
59fn generate_example_token() -> Result<(String, KeyPair), TokenError> {
60    // Create a test keypair
61    let keypair = KeyPair::new();
62
63    // Create a simple test biscuit with authorization rules
64    let biscuit_builder = biscuit!(
65        r#"
66            // Grant rights to alice for resource1
67            right("alice", "resource1", "read");
68            right("alice", "resource1", "write");
69        "#
70    );
71
72    // Build and serialize the token
73    let biscuit = biscuit_builder
74        .build(&keypair)
75        .map_err(|e| TokenError::biscuit_error(e))?;
76
77    let token_bytes = biscuit.to_vec().map_err(|e| TokenError::biscuit_error(e))?;
78
79    // Encode to base64 for transmission
80    Ok((encode_token(&token_bytes), keypair))
81}
Source

pub fn verification_error<S: Into<String>>(msg: S) -> Self

Create a new verification error

Source

pub fn invalid_key_format<S: Into<String>>(msg: S) -> Self

Create a new invalid key format error

Source

pub fn authorization_error<S: Into<String>>(msg: S) -> Self

Create a new authorization error

Source

pub fn generic<S: Into<String>>(msg: S) -> Self

Create a new generic error

Trait Implementations§

Source§

impl Debug for TokenError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for TokenError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for TokenError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<&str> for TokenError

Source§

fn from(err: &str) -> Self

Converts to this type from the input type.
Source§

impl From<FromHexError> for TokenError

Source§

fn from(err: FromHexError) -> Self

Converts to this type from the input type.
Source§

impl From<String> for TokenError

Source§

fn from(err: String) -> Self

Converts to this type from the input type.
Source§

impl From<Token> for TokenError

Source§

fn from(err: Token) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V