Membership

Struct Membership 

Source
pub struct Membership { /* private fields */ }
Expand description

A Membership provides cryptographically signed group affiliations.

Memberships link a member (via their IDCard) to a group (via the group’s public key). They can contain additional information like roles and are cryptographically signed by the group owner to prove authenticity.

§Example

use rust_bottle::*;
use rand::rngs::OsRng;

let rng = &mut OsRng;
let member_key = Ed25519Key::generate(rng);
let member_idcard = IDCard::new(&member_key.public_key_bytes());

let group_key = Ed25519Key::generate(rng);
let mut membership = Membership::new(&member_idcard, &group_key.public_key_bytes());
membership.set_info("role", "admin");

let signed = membership.sign(rng, &group_key).unwrap();

Implementations§

Source§

impl Membership

Source

pub fn new(member_idcard: &IDCard, group_public_key: &[u8]) -> Self

Create a new membership linking a member to a group.

§Arguments
  • member_idcard - The member’s IDCard
  • group_public_key - The group’s public key
§Returns

A new Membership instance (not yet signed)

§Example
use rust_bottle::*;
use rand::rngs::OsRng;

let rng = &mut OsRng;
let member_key = Ed25519Key::generate(rng);
let member_idcard = IDCard::new(&member_key.public_key_bytes());

let group_key = Ed25519Key::generate(rng);
let membership = Membership::new(&member_idcard, &group_key.public_key_bytes());
Source

pub fn set_info(&mut self, key: &str, value: &str)

Set information key-value pair.

Information fields can store application-specific data like roles, departments, or other metadata about the membership.

§Arguments
  • key - Information key
  • value - Information value
§Example
use rust_bottle::*;
use rand::rngs::OsRng;

let rng = &mut OsRng;
let member_key = Ed25519Key::generate(rng);
let member_idcard = IDCard::new(&member_key.public_key_bytes());
let group_key = Ed25519Key::generate(rng);

let mut membership = Membership::new(&member_idcard, &group_key.public_key_bytes());
membership.set_info("role", "admin");
membership.set_info("department", "Engineering");
Source

pub fn info(&self, key: &str) -> Option<&str>

Get information value by key.

§Arguments
  • key - Information key to look up
§Returns
  • Some(&str) if the key exists
  • None if the key is not found
Source

pub fn sign<R: RngCore>( &mut self, rng: &mut R, signer: &dyn Sign, ) -> Result<Vec<u8>>

Sign the membership with a private key.

This creates a cryptographic signature of the membership (excluding the signature field itself) and stores it. The signed membership is then serialized and returned.

§Arguments
  • rng - A random number generator
  • signer - A signer implementing the Sign trait (typically the group owner’s key)
§Returns
  • Ok(Vec<u8>) - Serialized signed membership
  • Err(BottleError::Serialization) - If serialization fails
  • Err(BottleError::VerifyFailed) - If signing fails
§Example
use rust_bottle::*;
use rand::rngs::OsRng;

let rng = &mut OsRng;
let member_key = Ed25519Key::generate(rng);
let member_idcard = IDCard::new(&member_key.public_key_bytes());
let group_key = Ed25519Key::generate(rng);

let mut membership = Membership::new(&member_idcard, &group_key.public_key_bytes());
let signed = membership.sign(rng, &group_key).unwrap();
Source

pub fn verify(&self, _group_idcard: &IDCard) -> Result<()>

Verify the membership signature.

§Note

This is a simplified implementation that only checks for the presence of a signature. Full verification would require extracting the signing key from the group’s IDCard and verifying the signature cryptographically.

§Arguments
  • _group_idcard - The group’s IDCard (currently not used)
§Returns
  • Ok(()) - If signature exists
  • Err(BottleError::VerifyFailed) - If signature is missing
Source

pub fn to_bytes(&self) -> Result<Vec<u8>>

Serialize the membership to bytes using bincode.

§Returns
  • Ok(Vec<u8>) - Serialized membership bytes
  • Err(BottleError::Serialization) - If serialization fails
Source

pub fn from_bytes(data: &[u8]) -> Result<Self>

Deserialize a membership from bytes.

§Arguments
  • data - Serialized membership bytes (from to_bytes)
§Returns
  • Ok(Membership) - Deserialized membership
  • Err(BottleError::Deserialization) - If deserialization fails

Trait Implementations§

Source§

impl Clone for Membership

Source§

fn clone(&self) -> Membership

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Membership

Source§

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

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

impl<'de> Deserialize<'de> for Membership

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Membership

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,