wireguard: make PrivateKey and PublicKey two distinct types

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-08-22 23:45:37 +00:00
parent 2f51a463b2
commit 1d8c818ec4
2 changed files with 79 additions and 19 deletions
+4 -4
View File
@@ -31,13 +31,13 @@ func (f *Config) Peers() int {
// InterfaceConfig represents the [Interface] section
type InterfaceConfig struct {
Address netip.Addr
PrivateKey BinaryKey
PrivateKey PrivateKey
ListenPort uint16
}
// PeerConfig represents a [Peer] section
type PeerConfig struct {
PublicKey BinaryKey
PublicKey PublicKey
Endpoint EndpointAddress
AllowedIPs []netip.Prefix
}
@@ -135,7 +135,7 @@ func (p interfaceConfig) Export() (InterfaceConfig, error) {
ListenPort: p.ListenPort,
}
out.PrivateKey, err = BinaryKeyFromBase64(p.PrivateKey)
out.PrivateKey, err = PrivateKeyFromBase64(p.PrivateKey)
if err != nil {
err = core.Wrap(err, "PrivateKey")
return InterfaceConfig{}, err
@@ -162,7 +162,7 @@ func (v *intermediateConfig) ExportPeer(i int) (PeerConfig, error) {
}
// PublicKey
out.PublicKey, err = BinaryKeyFromBase64(v.Peer.PublicKey[i])
out.PublicKey, err = PublicKeyFromBase64(v.Peer.PublicKey[i])
if err != nil {
err = core.Wrap(err, "PublicKey")
return out, err