wireguard

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package wireguard deals with wireguard config

Index

Constants

View Source
const (
	// PrivateKeySize is the length in bytes of a Wireguard Private Key
	PrivateKeySize = 32
	// PublicKeySize is the length in bytes of a Wireguard Public Key
	PublicKeySize = 32
)

Variables

View Source
var (
	// ErrInvalidKeySize indicates the key size is wrong
	ErrInvalidKeySize = errors.New("invalid key size")
	// ErrInvalidPrivateKey indicates the private key is invalid
	ErrInvalidPrivateKey = errors.New("invalid private key")
	// ErrInvalidPublicKey indicates the public key is invalid
	ErrInvalidPublicKey = errors.New("invalid public key")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Interface InterfaceConfig
	Peer      []PeerConfig
}

Config represents a wgN.conf file

func NewConfigFromReader

func NewConfigFromReader(r io.Reader) (*Config, error)

NewConfigFromReader parses a wgN.conf file

func (*Config) GetAddress

func (f *Config) GetAddress() netip.Addr

GetAddress is a shortcut to the interface's address

func (*Config) Peers

func (f *Config) Peers() int

Peers tells how many peers are described

func (*Config) WriteTo added in v0.4.7

func (f *Config) WriteTo(w io.Writer) (int64, error)

WriteTo writes a Wireguard Config onto the provided io.Writer

type EndpointAddress

type EndpointAddress struct {
	Host string
	Port uint16
}

EndpointAddress is a host:port pair to reach the Peer

func (*EndpointAddress) FromString

func (ep *EndpointAddress) FromString(s string) error

FromString sets the EndpointAddress from a given "[host]:port"

func (EndpointAddress) Name

func (ep EndpointAddress) Name() string

Name returns the first part of a hostname

func (EndpointAddress) String

func (ep EndpointAddress) String() string

func (*EndpointAddress) UnmarshalText added in v0.6.11

func (ep *EndpointAddress) UnmarshalText(b []byte) error

UnmarshalText loads an endpoint address from text data

type InterfaceConfig

type InterfaceConfig struct {
	Name       string
	Address    netip.Addr
	PrivateKey PrivateKey
	ListenPort uint16
}

InterfaceConfig represents the [Interface] section

type KeyPair

type KeyPair struct {
	PrivateKey PrivateKey
	PublicKey  PublicKey
}

KeyPair holds a Key pair

func NewKeyPair added in v0.3.0

func NewKeyPair() (KeyPair, error)

NewKeyPair creates a new KeyPair for Wireguard

func (*KeyPair) Validate added in v0.3.0

func (kp *KeyPair) Validate() error

Validate checks the PublicKey matches the PrivateKey, and sets the PublicKey if missing

type PeerConfig

type PeerConfig struct {
	Name       string
	PublicKey  PublicKey
	Endpoint   EndpointAddress
	AllowedIPs []netip.Prefix
}

PeerConfig represents a [Peer] section

type PrivateKey added in v0.2.0

type PrivateKey [PrivateKeySize]byte

PrivateKey is a binary Wireguard Private Key

func NewPrivateKey added in v0.3.0

func NewPrivateKey() (PrivateKey, error)

NewPrivateKey creates a new PrivateKey

func PrivateKeyFromBase64 added in v0.2.0

func PrivateKeyFromBase64(data string) (PrivateKey, error)

PrivateKeyFromBase64 decodes a base64-based string into a PrivateKey

func (PrivateKey) Equal added in v0.2.0

func (key PrivateKey) Equal(alter PrivateKey) bool

Equal checks if two private keys are identical

func (PrivateKey) IsZero added in v0.2.0

func (key PrivateKey) IsZero() bool

IsZero tells if the key hasn't been set

func (PrivateKey) MarshalJSON added in v0.4.4

func (key PrivateKey) MarshalJSON() ([]byte, error)

MarshalJSON encodes the key for JSON, omitting empty.

func (PrivateKey) MarshalYAML added in v0.4.4

func (key PrivateKey) MarshalYAML() (any, error)

MarshalYAML encodes the key for YAML, omitting empty.

func (PrivateKey) Public added in v0.3.0

func (key PrivateKey) Public() PublicKey

Public generates the corresponding PublicKey

func (PrivateKey) String added in v0.2.0

func (key PrivateKey) String() string

func (*PrivateKey) UnmarshalText added in v0.6.11

func (key *PrivateKey) UnmarshalText(b []byte) error

UnmarshalText loads the value from base64

type PublicKey added in v0.2.0

type PublicKey [PublicKeySize]byte

PublicKey is a binary Wireguard Public Key

func PublicKeyFromBase64 added in v0.2.0

func PublicKeyFromBase64(data string) (PublicKey, error)

PublicKeyFromBase64 decodes a base64-based string into a PublicKey

func (PublicKey) Equal added in v0.2.0

func (pub PublicKey) Equal(alter PublicKey) bool

Equal checks if two public keys are identical

func (PublicKey) IsZero added in v0.2.0

func (pub PublicKey) IsZero() bool

IsZero tells if the key hasn't been set

func (PublicKey) MarshalJSON added in v0.4.4

func (pub PublicKey) MarshalJSON() ([]byte, error)

MarshalJSON encodes the key for JSON, omitting empty.

func (PublicKey) MarshalYAML added in v0.4.4

func (pub PublicKey) MarshalYAML() (any, error)

MarshalYAML encodes the key for YAML, omitting empty.

func (PublicKey) String added in v0.2.0

func (pub PublicKey) String() string

func (*PublicKey) UnmarshalText added in v0.6.11

func (pub *PublicKey) UnmarshalText(b []byte) error

UnmarshalText loads the value from base64

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL