wireguard: make KeyPairs solid

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-08-24 19:49:59 +00:00
parent 60e2687d04
commit 30a7bceda3
3 changed files with 30 additions and 47 deletions
+6 -8
View File
@@ -169,15 +169,13 @@ func (kp *KeyPair) Validate() error {
}
// NewKeyPair creates a new KeyPair for Wireguard
func NewKeyPair() (*KeyPair, error) {
key, err := NewPrivateKey()
if err != nil {
return nil, err
}
func NewKeyPair() (KeyPair, error) {
var out KeyPair
out := &KeyPair{
PrivateKey: key,
PublicKey: key.Public(),
key, err := NewPrivateKey()
if err == nil {
out.PrivateKey = key
out.PublicKey = key.Public()
}
return out, nil
}