distribute/crypto/provider
Types
pub type ProviderState {
ProviderState
}
Constructors
-
ProviderState
pub type SecureContext {
SecureContext
}
Constructors
-
SecureContext
Values
pub fn close(state: ProviderState) -> Nil
Close the provider and release resources.
Called when the provider is shutting down. Implementations should clean up any allocated resources and zero sensitive memory.
pub fn decrypt(
context: SecureContext,
cipher: BitArray,
) -> Result(BitArray, String)
Decrypt ciphertext using a secure context.
Decrypts the given data using the established secure context.
Arguments
context- Secure context from completed handshakecipher- Ciphertext data to decrypt
Returns
Ok(plaintext)- Decrypted dataError(reason)- Decryption failed (e.g., tampered data)
pub fn encrypt(
context: SecureContext,
plain: BitArray,
) -> Result(BitArray, String)
Encrypt plaintext using a secure context.
Encrypts the given data using the established secure context.
Arguments
context- Secure context from completed handshakeplain- Plaintext data to encrypt
Returns
Ok(ciphertext)- Encrypted dataError(reason)- Encryption failed
pub fn handle_key_exchange(
state: ProviderState,
incoming: BitArray,
) -> #(
option.Option(BitArray),
ProviderState,
option.Option(SecureContext),
)
Handle an incoming key exchange message.
Processes a message from the peer during key exchange and returns the next state of the protocol.
Arguments
state- Current provider stateincoming- Message received from peer
Returns
Tuple of (optional_response, updated_state, optional_secure_context). When secure_context is Some, the handshake is complete.
pub fn init() -> ProviderState
Initialize the provider state.
Called once when the provider is started. Implementations must allocate any required resources and prepare for key exchange operations.
Returns
Initial ProviderState for subsequent operations.
pub fn rekey(
context: SecureContext,
) -> Result(SecureContext, String)
Rotate the encryption key for a secure context.
Derives a new encryption key while maintaining the connection. The old key is discarded.
Arguments
context- Current secure context
Returns
Ok(new_context)- Context with new key materialError(reason)- Rekey operation failed
pub fn start_key_exchange(
state: ProviderState,
local_params: BitArray,
) -> #(BitArray, ProviderState)
Start a key exchange with local parameters.
Initiates the key exchange protocol by generating the first message to send to the peer.
Arguments
state- Current provider statelocal_params- Local parameters for key exchange
Returns
Tuple of (outgoing_message, updated_state).