Documentation
¶
Overview ¶
Package wireguard deals with wireguard config
Index ¶
- Constants
- Variables
- type Config
- type EndpointAddress
- type InterfaceConfig
- type KeyPair
- type PeerConfig
- type PrivateKey
- func (key PrivateKey) Equal(alter PrivateKey) bool
- func (key PrivateKey) IsZero() bool
- func (key PrivateKey) MarshalJSON() ([]byte, error)
- func (key PrivateKey) MarshalYAML() (any, error)
- func (key PrivateKey) Public() PublicKey
- func (key PrivateKey) String() string
- func (key *PrivateKey) UnmarshalText(b []byte) error
- type PublicKey
Constants ¶
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 ¶
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 ¶
NewConfigFromReader parses a wgN.conf file
func (*Config) GetAddress ¶
GetAddress is a shortcut to the interface's address
type EndpointAddress ¶
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
NewKeyPair creates a new KeyPair for Wireguard
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
PublicKeyFromBase64 decodes a base64-based string into a PublicKey
func (PublicKey) MarshalJSON ¶ added in v0.4.4
MarshalJSON encodes the key for JSON, omitting empty.
func (PublicKey) MarshalYAML ¶ added in v0.4.4
MarshalYAML encodes the key for YAML, omitting empty.
func (*PublicKey) UnmarshalText ¶ added in v0.6.11
UnmarshalText loads the value from base64