View Source Wireguardex (Wireguardex v0.3.2)

Wireguardex is an Elixir library for configuring WireGuard interfaces. It uses Rust NIFs for performance and safety.

This is the main module, providing the API for interface configuration and utilities such as key generation.

Link to this section Summary

Functions

Add a peer to a Device using a config for the peer. A config can be generated using a PeerConfigBuilder.

Delete a Device by its interface name.

Generates a random preshared key. It is returned as a base64 string.

Generates a random private key. It is returned as a base64 string.

Get a Device by its interface name.

Return a private key's public key as a base64 string.

Get a list of interface names of WireGuard devices.

Remove a peer from a Device by the peer's public key.

Set a Device by its interface name with a config. The config can be generated using a DeviceConfigBuilder.

Link to this section Types

@type device() :: Wireguardex.Device.t()
@type device_config() :: Wireguardex.DeviceConfig.t()
@type key() :: String.t()
@type name() :: String.t()
@type peer_config() :: Wireguardex.PeerConfig.t()
@type peer_stats() :: Wireguardex.PeerStats.t()

Link to this section Functions

@spec add_peer(name(), peer_config()) :: :ok | {:error, String.t()}

Add a peer to a Device using a config for the peer. A config can be generated using a PeerConfigBuilder.

Returns :ok if successful. {:error, error_info} will be returned if adding the peer to the device fails.

@spec delete_device(name()) :: :ok | {:error, String.t()}

Delete a Device by its interface name.

Returns :ok if successful. {:error, error_info} will be returned if deleting the device fails.

Link to this function

generate_preshared_key()

View Source
@spec generate_preshared_key() :: key()

Generates a random preshared key. It is returned as a base64 string.

@spec generate_private_key() :: key()

Generates a random private key. It is returned as a base64 string.

@spec get_device(name()) :: {:ok, device()} | {:error, String.t()}

Get a Device by its interface name.

Returns {:ok, Device} if successful. {:error, error_info} will be returned if getting the device fails.

Link to this function

get_public_key(private_key)

View Source
@spec get_public_key(key()) :: {:ok, key()} | {:error, String.t()}

Return a private key's public key as a base64 string.

Returns {:ok, public_key} if successful. {:error, error_info} will be returned if if getting the public key fails.

@spec list_devices() :: {:ok, [device()]} | {:error, String.t()}

Get a list of interface names of WireGuard devices.

Returns {:ok, [...]} if successful. {:error, error_info} will be returned if listing device interface names fails.

Link to this function

remove_peer(name, public_key)

View Source
@spec remove_peer(name(), key()) :: :ok | {:error, String.t()}

Remove a peer from a Device by the peer's public key.

Returns :ok if successful. {:error, error_info} will be returned if removing the peer from the device fails.

Link to this function

set_device(device_config, name)

View Source
@spec set_device(device_config(), name()) :: :ok | {:error, String.t()}

Set a Device by its interface name with a config. The config can be generated using a DeviceConfigBuilder.

Note if no device is present, a new one will be created for the given interface name.

Returns :ok if successful. {:error, error_info} will be returned if setting the device fails.