Validate keyring input

Linc helped me discover this bug by being into pushing buttons on my
kc71 and watching the colors change.
This commit is contained in:
Stephen McQuay 2018-02-25 09:42:48 -08:00
parent a00e058178
commit e18aee5b4f
Signed by untrusted user: sm
GPG Key ID: 4E4B72F479BA3CE5

View File

@ -15,6 +15,15 @@ import (
// NewKeyPair creates and adds a new OpenPGP keypair to an existing keyring. // NewKeyPair creates and adds a new OpenPGP keypair to an existing keyring.
func NewKeyPair(root, name, email string) error { func NewKeyPair(root, name, email string) error {
if name == "" {
return errors.New("name cannot be empty")
}
if email == "" {
return errors.New("email cannot be empty")
}
if strings.ContainsAny(email, "()<>\x00") {
return fmt.Errorf("email %q contains invalid chars", email)
}
if err := ensureDir(root); err != nil { if err := ensureDir(root); err != nil {
return errors.Wrap(err, "can't find or create pgp dir") return errors.Wrap(err, "can't find or create pgp dir")
} }