pub enum PublicKey {
Ed25519(PublicKey),
P256(PublicKey),
}Expand description
the public part of a KeyPair
Variants§
Implementations§
Source§impl PublicKey
impl PublicKey
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
serializes to a byte array
Examples found in repository?
examples/token_verification.rs (line 23)
7fn main() -> Result<(), TokenError> {
8 // Generate an example token
9 let root_keypair = Arc::new(KeyPair::new());
10 let token_base64 = generate_example_token(root_keypair.clone())?;
11 println!("Generated token: {}\n", token_base64);
12
13 // Example 1: Basic verification
14 println!("Example 1: Basic verification");
15 verify_token(&token_base64, root_keypair.public(), "alice", "resource1")?;
16 println!("✅ Basic verification successful\n");
17
18 // Example 2: Service chain verification
19 println!("Example 2: Service chain verification");
20
21 // Create service node keypairs
22 let service1_keypair = KeyPair::new();
23 let service1_pk_hex = hex::encode(service1_keypair.public().to_bytes());
24 let service1_public_key = format!("ed25519/{}", service1_pk_hex);
25
26 let service2_keypair = KeyPair::new();
27 let service2_pk_hex = hex::encode(service2_keypair.public().to_bytes());
28 let service2_public_key = format!("ed25519/{}", service2_pk_hex);
29
30 // Define service nodes
31 let service_nodes = vec![
32 ServiceNode {
33 component: "node1".to_string(),
34 public_key: service1_public_key.clone(),
35 },
36 ServiceNode {
37 component: "node2".to_string(),
38 public_key: service2_public_key.clone(),
39 },
40 ];
41
42 // Generate a token with service chain
43 let chain_token = generate_service_chain_token(
44 root_keypair.clone(),
45 service1_public_key,
46 service2_public_key,
47 )?;
48
49 // attenuate the token for node1
50 let attenuated_token = add_service_node_attenuation(
51 decode_token(&chain_token)?,
52 root_keypair.public(),
53 "resource1",
54 &service1_keypair,
55 )?;
56
57 // attenuate the token for node2
58 let attenuated_token2 = add_service_node_attenuation(
59 attenuated_token,
60 root_keypair.public(),
61 "resource1",
62 &service2_keypair,
63 )?;
64
65 // Verify with service chain
66 verify_service_chain_token(
67 &encode_token(&attenuated_token2),
68 root_keypair.public(),
69 "alice",
70 "resource1",
71 service_nodes,
72 None,
73 )?;
74 println!("✅ Service chain verification successful\n");
75
76 // Example 3: Verification with key from string
77 println!("Example 3: Verification with key from string");
78
79 // Convert public key to string format and back
80 let pk_hex = hex::encode(root_keypair.public().to_bytes());
81 let pk_str = format!("ed25519/{}", pk_hex);
82 let parsed_pk = biscuit_key_from_string(pk_str)?;
83
84 // Verify with parsed key
85 verify_token(&token_base64, parsed_pk, "alice", "resource1")?;
86 println!("✅ Verification with key from string successful");
87
88 Ok(())
89}Sourcepub fn to_bytes_hex(&self) -> String
pub fn to_bytes_hex(&self) -> String
serializes to an hex-encoded string
Sourcepub fn from_bytes(
bytes: &[u8],
algorithm: Algorithm,
) -> Result<PublicKey, Format>
pub fn from_bytes( bytes: &[u8], algorithm: Algorithm, ) -> Result<PublicKey, Format>
deserializes from a byte array
Sourcepub fn from_bytes_hex(
str: &str,
algorithm: Algorithm,
) -> Result<PublicKey, Format>
pub fn from_bytes_hex( str: &str, algorithm: Algorithm, ) -> Result<PublicKey, Format>
deserializes from an hex-encoded string
pub fn from_proto(key: &PublicKey) -> Result<PublicKey, Format>
pub fn to_proto(&self) -> PublicKey
pub fn from_der_with_algorithm( bytes: &[u8], algorithm: Algorithm, ) -> Result<PublicKey, Format>
pub fn from_der(bytes: &[u8]) -> Result<PublicKey, Format>
pub fn from_pem_with_algorithm( str: &str, algorithm: Algorithm, ) -> Result<PublicKey, Format>
pub fn from_pem(str: &str) -> Result<PublicKey, Format>
pub fn to_der(&self) -> Result<Vec<u8>, Format>
pub fn to_pem(&self) -> Result<String, Format>
pub fn verify_signature( &self, data: &[u8], signature: &Signature, ) -> Result<(), Format>
pub fn algorithm(&self) -> Algorithm
pub fn algorithm_string(&self) -> &str
pub fn print(&self) -> String
Trait Implementations§
Source§impl RootKeyProvider for &PublicKey
impl RootKeyProvider for &PublicKey
Source§impl RootKeyProvider for PublicKey
impl RootKeyProvider for PublicKey
Source§impl ToAnyParam for PublicKey
impl ToAnyParam for PublicKey
fn to_any_param(&self) -> AnyParam
impl Copy for PublicKey
impl Eq for PublicKey
impl StructuralPartialEq for PublicKey
Auto Trait Implementations§
impl Freeze for PublicKey
impl RefUnwindSafe for PublicKey
impl Send for PublicKey
impl Sync for PublicKey
impl Unpin for PublicKey
impl UnwindSafe for PublicKey
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