Packages
Typed distributed messaging for Gleam on the BEAM.
Retired package: Deprecated - The project needs to be redesigned around a much smaller and clearer core.
Current section
Files
Jump to
Current section
Files
src/distribute@crypto@provider.erl
-module(distribute@crypto@provider).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/distribute/crypto/provider.gleam").
-export([init/0, start_key_exchange/2, handle_key_exchange/2, encrypt/2, decrypt/2, rekey/1, close/1]).
-export_type([provider_state/0, secure_context/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type provider_state() :: provider_state.
-type secure_context() :: secure_context.
-file("src/distribute/crypto/provider.gleam", 26).
?DOC(
" Initialize the provider state.\n"
"\n"
" Called once when the provider is started. Implementations must allocate\n"
" any required resources and prepare for key exchange operations.\n"
"\n"
" ## Returns\n"
"\n"
" Initial `ProviderState` for subsequent operations.\n"
).
-spec init() -> provider_state().
init() ->
provider_state.
-file("src/distribute/crypto/provider.gleam", 44).
?DOC(
" Start a key exchange with local parameters.\n"
"\n"
" Initiates the key exchange protocol by generating the first message\n"
" to send to the peer.\n"
"\n"
" ## Arguments\n"
"\n"
" - `state` - Current provider state\n"
" - `local_params` - Local parameters for key exchange\n"
"\n"
" ## Returns\n"
"\n"
" Tuple of (outgoing_message, updated_state).\n"
).
-spec start_key_exchange(provider_state(), bitstring()) -> {bitstring(),
provider_state()}.
start_key_exchange(State, Local_params) ->
{Local_params, State}.
-file("src/distribute/crypto/provider.gleam", 66).
?DOC(
" Handle an incoming key exchange message.\n"
"\n"
" Processes a message from the peer during key exchange and returns\n"
" the next state of the protocol.\n"
"\n"
" ## Arguments\n"
"\n"
" - `state` - Current provider state\n"
" - `incoming` - Message received from peer\n"
"\n"
" ## Returns\n"
"\n"
" Tuple of (optional_response, updated_state, optional_secure_context).\n"
" When secure_context is Some, the handshake is complete.\n"
).
-spec handle_key_exchange(provider_state(), bitstring()) -> {gleam@option:option(bitstring()),
provider_state(),
gleam@option:option(secure_context())}.
handle_key_exchange(State, _) ->
{none, State, none}.
-file("src/distribute/crypto/provider.gleam", 87).
?DOC(
" Encrypt plaintext using a secure context.\n"
"\n"
" Encrypts the given data using the established secure context.\n"
"\n"
" ## Arguments\n"
"\n"
" - `context` - Secure context from completed handshake\n"
" - `plain` - Plaintext data to encrypt\n"
"\n"
" ## Returns\n"
"\n"
" - `Ok(ciphertext)` - Encrypted data\n"
" - `Error(reason)` - Encryption failed\n"
).
-spec encrypt(secure_context(), bitstring()) -> {ok, bitstring()} |
{error, binary()}.
encrypt(_, _) ->
{error, <<"not implemented"/utf8>>}.
-file("src/distribute/crypto/provider.gleam", 107).
?DOC(
" Decrypt ciphertext using a secure context.\n"
"\n"
" Decrypts the given data using the established secure context.\n"
"\n"
" ## Arguments\n"
"\n"
" - `context` - Secure context from completed handshake\n"
" - `cipher` - Ciphertext data to decrypt\n"
"\n"
" ## Returns\n"
"\n"
" - `Ok(plaintext)` - Decrypted data\n"
" - `Error(reason)` - Decryption failed (e.g., tampered data)\n"
).
-spec decrypt(secure_context(), bitstring()) -> {ok, bitstring()} |
{error, binary()}.
decrypt(_, _) ->
{error, <<"not implemented"/utf8>>}.
-file("src/distribute/crypto/provider.gleam", 127).
?DOC(
" Rotate the encryption key for a secure context.\n"
"\n"
" Derives a new encryption key while maintaining the connection.\n"
" The old key is discarded.\n"
"\n"
" ## Arguments\n"
"\n"
" - `context` - Current secure context\n"
"\n"
" ## Returns\n"
"\n"
" - `Ok(new_context)` - Context with new key material\n"
" - `Error(reason)` - Rekey operation failed\n"
).
-spec rekey(secure_context()) -> {ok, secure_context()} | {error, binary()}.
rekey(_) ->
{error, <<"not implemented"/utf8>>}.
-file("src/distribute/crypto/provider.gleam", 135).
?DOC(
" Close the provider and release resources.\n"
"\n"
" Called when the provider is shutting down. Implementations should\n"
" clean up any allocated resources and zero sensitive memory.\n"
).
-spec close(provider_state()) -> nil.
close(_) ->
nil.