Browse Source

wireguard: implement MarshalYAML for PrivateKey and PublicKey

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/1/head
Alejandro Mery 1 year ago
parent
commit
4514b44211
  1. 18
      pkg/wireguard/keys.go

18
pkg/wireguard/keys.go

@ -70,6 +70,24 @@ func encodeKeyJSON(s string) ([]byte, error) {
return out, nil
}
// MarshalYAML encodes the key for YAML, omiting empty.
func (key PrivateKey) MarshalYAML() (any, error) {
return encodeKeyYAML(key.String())
}
// MarshalYAML encodes the key for YAML, omiting empty.
func (pub PublicKey) MarshalYAML() (any, error) {
return encodeKeyYAML(pub.String())
}
func encodeKeyYAML(s string) (any, error) {
if s == "" {
return nil, nil
}
return s, nil
}
// IsZero tells if the key hasn't been set
func (key PrivateKey) IsZero() bool {
var zero PrivateKey

Loading…
Cancel
Save