diff --git a/pkg/wireguard/config.go b/pkg/wireguard/config.go index 92f7b21..ab22c69 100644 --- a/pkg/wireguard/config.go +++ b/pkg/wireguard/config.go @@ -1,7 +1,6 @@ package wireguard import ( - "encoding/base64" "errors" "fmt" "io" @@ -32,13 +31,13 @@ func (f *Config) Peers() int { // InterfaceConfig represents the [Interface] section type InterfaceConfig struct { Address netip.Addr - PrivateKey []byte + PrivateKey BinaryKey ListenPort uint16 } // PeerConfig represents a [Peer] section type PeerConfig struct { - PublicKey []byte + PublicKey BinaryKey Endpoint EndpointAddress AllowedIPs []netip.Prefix } @@ -129,19 +128,19 @@ type interfaceConfig struct { } func (p interfaceConfig) Export() (InterfaceConfig, error) { + var err error + out := InterfaceConfig{ Address: p.Address, ListenPort: p.ListenPort, } - b, err := base64.StdEncoding.DecodeString(p.PrivateKey) + out.PrivateKey, err = BinaryKeyFromBase64(p.PrivateKey) if err != nil { err = core.Wrap(err, "PrivateKey") return InterfaceConfig{}, err } - out.PrivateKey = b - return out, nil } @@ -163,8 +162,7 @@ func (v *intermediateConfig) ExportPeer(i int) (PeerConfig, error) { } // PublicKey - s = v.Peer.PublicKey[i] - out.PublicKey, err = base64.StdEncoding.DecodeString(s) + out.PublicKey, err = BinaryKeyFromBase64(v.Peer.PublicKey[i]) if err != nil { err = core.Wrap(err, "PublicKey") return out, err