Browse Source

wireguard: implement UnmarshalText for PrivateKey and PublicKey

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/32/head
Alejandro Mery 10 months ago
parent
commit
7c811d7813
  1. 22
      pkg/wireguard/keys.go

22
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())

Loading…
Cancel
Save