From 7c811d7813683522a31714be276fa14e95e68ac7 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Fri, 1 Sep 2023 19:54:36 +0000 Subject: [PATCH 1/2] wireguard: implement UnmarshalText for PrivateKey and PublicKey Signed-off-by: Alejandro Mery --- pkg/wireguard/keys.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pkg/wireguard/keys.go b/pkg/wireguard/keys.go index fe21f98..1b3ef20 100644 --- a/pkg/wireguard/keys.go +++ b/pkg/wireguard/keys.go @@ -51,6 +51,28 @@ func (pub PublicKey) String() string { } } +// UnmarshalText loads the value from base64 +func (key *PrivateKey) UnmarshalText(b []byte) error { + v, err := PrivateKeyFromBase64(string(b)) + if err != nil { + return err + } + + *key = v + return nil +} + +// UnmarshalText loads the value from base64 +func (pub *PublicKey) UnmarshalText(b []byte) error { + v, err := PublicKeyFromBase64(string(b)) + if err != nil { + return err + } + + *pub = v + return nil +} + // MarshalJSON encodes the key for JSON, omitting empty. func (key PrivateKey) MarshalJSON() ([]byte, error) { return encodeKeyJSON(key.String()) -- 2.17.1 From 125a4c0dbe7218c943a7ac3990b623c1e295ec61 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Fri, 1 Sep 2023 20:00:42 +0000 Subject: [PATCH 2/2] wireguard: implement EndpointAddress.UnmarshalText Signed-off-by: Alejandro Mery --- pkg/wireguard/config.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/wireguard/config.go b/pkg/wireguard/config.go index 9309bd5..c8ad1dd 100644 --- a/pkg/wireguard/config.go +++ b/pkg/wireguard/config.go @@ -107,6 +107,11 @@ func (ep EndpointAddress) String() string { } } +// UnmarshalText loads an endpoint address from text data +func (ep *EndpointAddress) UnmarshalText(b []byte) error { + return ep.FromString(string(b)) +} + // FromString sets the EndpointAddress from a given "[host]:port" func (ep *EndpointAddress) FromString(s string) error { host, port, err := core.SplitHostPort(s) -- 2.17.1