From f5ee63e5aa7992cece21d948843bfc277df2bdb7 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Tue, 22 Aug 2023 19:38:34 +0000 Subject: [PATCH] wireguard: cleanup Config parser using BinaryKey Signed-off-by: Alejandro Mery --- pkg/wireguard/config.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) 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