go-pgp-tool/pgpcrypt/keys.go

31 lines
559 B
Go
Raw Normal View History

2018-03-08 10:24:33 +00:00
package pgpcrypt
import (
"io"
"golang.org/x/crypto/openpgp"
)
// ReadKeyFile - read key from file
func ReadKeyFile(r io.Reader) (openpgp.EntityList, error) {
keys, err := openpgp.ReadArmoredKeyRing(r)
2018-03-09 06:04:27 +00:00
if err != nil || len(keys) == 0 {
2018-03-08 10:24:33 +00:00
keys, err = openpgp.ReadKeyRing(r)
if err != nil {
return nil, err
}
}
return keys, nil
}
// CombineKeys - combine key
func CombineKeys(keys ...openpgp.EntityList) openpgp.EntityList {
var keyList openpgp.EntityList
for _, key := range keys {
keyList = append(keyList, key...)
}
return keyList
}