Skip to main content

MembershipToken

Struct MembershipToken 

Source
pub struct MembershipToken {
    pub public_key: [u8; 32],
    pub mesh_id: [u8; 4],
    pub callsign: [u8; 12],
    pub issued_at_ms: u64,
    pub expires_at_ms: u64,
    pub authority_signature: [u8; 64],
}
Expand description

A membership token binding a device to a callsign within a mesh

Issued by the mesh authority and verifiable by any node.

Fields§

§public_key: [u8; 32]

Member’s Ed25519 public key

§mesh_id: [u8; 4]

Mesh ID this token is valid for (4 bytes from MeshGenesis)

§callsign: [u8; 12]

Assigned callsign (up to 12 chars, null-padded)

§issued_at_ms: u64

When this token was issued (milliseconds since Unix epoch)

§expires_at_ms: u64

When this token expires (milliseconds since Unix epoch) 0 means no expiration

§authority_signature: [u8; 64]

Authority’s Ed25519 signature over the above fields

Implementations§

Source§

impl MembershipToken

Source

pub fn issue( authority: &DeviceIdentity, genesis: &MeshGenesis, member_public_key: [u8; 32], callsign: &str, validity_ms: u64, ) -> Self

Issue a new membership token

§Arguments
  • authority - The mesh authority’s identity (must be mesh creator)
  • genesis - The mesh genesis containing mesh_id
  • member_public_key - The new member’s public key
  • callsign - Human-readable callsign (max 12 chars)
  • validity_ms - How long the token is valid (0 = forever)
§Panics

Panics if callsign is longer than 12 characters.

Source

pub fn issue_at( authority: &DeviceIdentity, mesh_id: [u8; 4], member_public_key: [u8; 32], callsign: &str, issued_at_ms: u64, expires_at_ms: u64, ) -> Self

Issue a token with explicit timestamps (for testing)

Source

pub fn verify(&self, authority_public_key: &[u8; 32]) -> bool

Verify the token’s authority signature

§Arguments
  • authority_public_key - The mesh authority’s public key
§Returns

true if the signature is valid

Source

pub fn is_expired(&self, now_ms: u64) -> bool

Check if the token has expired

§Arguments
  • now_ms - Current time in milliseconds since epoch
§Returns

true if the token has expired (expires_at_ms != 0 and now_ms > expires_at_ms)

Source

pub fn is_valid(&self, authority_public_key: &[u8; 32], now_ms: u64) -> bool

Check if the token is valid (signature OK and not expired)

§Arguments
  • authority_public_key - The mesh authority’s public key
  • now_ms - Current time in milliseconds since epoch
Source

pub fn callsign_str(&self) -> &str

Get the callsign as a string (trimmed of null padding)

Source

pub fn mesh_id_hex(&self) -> String

Get the mesh_id as a hex string (e.g., “A1B2C3D4”)

Source

pub fn encode(&self) -> [u8; 128]

Encode token to wire format (128 bytes)

Source

pub fn decode(data: &[u8]) -> Option<Self>

Decode token from wire format

Returns None if data is not exactly 128 bytes.

Trait Implementations§

Source§

impl Clone for MembershipToken

Source§

fn clone(&self) -> MembershipToken

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 MembershipToken

Source§

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

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

impl PartialEq for MembershipToken

Source§

fn eq(&self, other: &MembershipToken) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for MembershipToken

Source§

impl StructuralPartialEq for MembershipToken

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.