pub struct FormationKey { /* private fields */ }Expand description
Formation key for shared secret authentication
All nodes in a formation share this key. Used for challenge-response authentication during connection establishment.
Implementations§
Source§impl FormationKey
impl FormationKey
Sourcepub fn new(formation_id: &str, shared_secret: &[u8; 32]) -> Self
pub fn new(formation_id: &str, shared_secret: &[u8; 32]) -> Self
Create a new formation key from a shared secret
The key is derived using HKDF-SHA256 with the formation ID as context, ensuring different formations have different derived keys even with the same base secret.
Sourcepub fn from_base64(
formation_id: &str,
base64_secret: &str,
) -> Result<Self, SecurityError>
pub fn from_base64( formation_id: &str, base64_secret: &str, ) -> Result<Self, SecurityError>
Create a formation key from a base64-encoded shared secret
§Key Derivation
- If the decoded secret is exactly 32 bytes, it’s used directly
- Otherwise, SHA-256 is used to derive a 32-byte key from the input
Sourcepub fn generate_secret() -> String
pub fn generate_secret() -> String
Generate a random 32-byte shared secret (for initial setup)
Returns base64-encoded 32-byte random secret.
Sourcepub fn formation_id(&self) -> &str
pub fn formation_id(&self) -> &str
Get the formation ID
Sourcepub fn create_challenge(&self) -> ([u8; 32], [u8; 32])
pub fn create_challenge(&self) -> ([u8; 32], [u8; 32])
Create a challenge for the peer to respond to
Returns tuple of (nonce, expected_response).
Sourcepub fn respond_to_challenge(&self, nonce: &[u8]) -> [u8; 32]
pub fn respond_to_challenge(&self, nonce: &[u8]) -> [u8; 32]
Respond to a challenge from a peer
Trait Implementations§
Source§impl Clone for FormationKey
impl Clone for FormationKey
Source§fn clone(&self) -> FormationKey
fn clone(&self) -> FormationKey
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for FormationKey
impl RefUnwindSafe for FormationKey
impl Send for FormationKey
impl Sync for FormationKey
impl Unpin for FormationKey
impl UnsafeUnpin for FormationKey
impl UnwindSafe for FormationKey
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