You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

36 lines
730 B

package wireguard
import (
"bytes"
"encoding/base64"
)
// BinaryKey is a binary blob
type BinaryKey []byte
func (k BinaryKey) String() string {
return base64.StdEncoding.EncodeToString(k)
}
// IsZero tells if the key hasn't been set
func (k BinaryKey) IsZero() bool {
return len(k) == 0
}
// Equal checks if two keys are identical
func (k BinaryKey) Equal(alter BinaryKey) bool {
return bytes.Equal(k, alter)
}
// BinaryKeyFromBase64 decodes a base64-based string into
// a [BinaryKey]
func BinaryKeyFromBase64(data string) (BinaryKey, error) {
b, err := base64.StdEncoding.DecodeString(data)
return BinaryKey(b), err
}
// KeyPair holds a Key pair
type KeyPair struct {
PrivateKey BinaryKey
PublicKey BinaryKey
}