Amarula.Protocol.Socket.ConnectionValidator (amarula v0.1.0)

View Source

Static validation functions for WhatsApp WebSocket handshake.

This module provides pure functions for validating handshake messages and generating appropriate responses. The Connection orchestrates the actual sending and state management.

Summary

Functions

Generate initial ClientHello message for handshake start.

Get the completed noise state for ongoing communication.

Check if handshake is completed.

Process handshake completion message.

Process ServerHello message and generate ClientFinish response.

Types

handshake_state()

@type handshake_state() :: %{
  noise_state: Amarula.Protocol.Crypto.NoiseHandler.noise_state(),
  auth_creds: Amarula.Protocol.Auth.AuthUtils.auth_creds(),
  socket_config: Amarula.Protocol.Auth.AuthUtils.socket_config(),
  handshake_step: atom()
}

message_result()

@type message_result() :: {:ok, binary(), handshake_state()} | {:error, term()}

validation_result()

@type validation_result() :: {:ok, handshake_state()} | {:error, term()}

Functions

generate_client_hello(auth_creds, socket_config)

Generate initial ClientHello message for handshake start.

Returns the encoded ClientHello message and initial handshake state.

get_noise_state(state)

Get the completed noise state for ongoing communication.

handshake_completed?(state)

@spec handshake_completed?(handshake_state()) :: boolean()

Check if handshake is completed.

process_handshake_complete(state, message_data)

@spec process_handshake_complete(handshake_state(), binary()) ::
  {:ok, handshake_state()} | {:error, term()}

Process handshake completion message.

Handles the final handshake message from the server.

process_server_hello(state, message_data)

@spec process_server_hello(handshake_state(), binary()) :: message_result()

Process ServerHello message and generate ClientFinish response.

Takes the incoming ServerHello message and returns the ClientFinish message to send back to the server.