town/sshkey/sshkey.go

24 lines
361 B
Go
Raw Permalink Normal View History

2023-03-04 01:15:09 +00:00
package sshkey
import (
"bytes"
"errors"
"os/exec"
)
const skgpath = "/usr/bin/ssh-keygen"
func ValidKey(key string) (valid bool, err error) {
cmd := exec.Command(skgpath, "-l", "-f", "-")
cmd.Stdin = bytes.NewBuffer([]byte(key))
err = cmd.Run()
if err == nil {
valid = true
} else if errors.Is(&exec.ExitError{}, err) {
err = nil
}
return
}