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
impl TokenError
Sourcepub fn biscuit_error<E: StdError>(err: E) -> Self
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
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}Sourcepub fn verification_error<S: Into<String>>(msg: S) -> Self
pub fn verification_error<S: Into<String>>(msg: S) -> Self
Create a new verification error
Sourcepub fn invalid_key_format<S: Into<String>>(msg: S) -> Self
pub fn invalid_key_format<S: Into<String>>(msg: S) -> Self
Create a new invalid key format error
Create a new authorization error
Trait Implementations§
Source§impl Debug for TokenError
impl Debug for TokenError
Source§impl Display for TokenError
impl Display for TokenError
Source§impl Error for TokenError
impl Error for TokenError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
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
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl From<&str> for TokenError
impl From<&str> for TokenError
Source§impl From<FromHexError> for TokenError
impl From<FromHexError> for TokenError
Source§fn from(err: FromHexError) -> Self
fn from(err: FromHexError) -> Self
Converts to this type from the input type.
Source§impl From<String> for TokenError
impl From<String> for TokenError
Auto Trait Implementations§
impl Freeze for TokenError
impl RefUnwindSafe for TokenError
impl Send for TokenError
impl Sync for TokenError
impl Unpin for TokenError
impl UnwindSafe for TokenError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more