47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
package go_pgp
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
|
|
"github.com/ProtonMail/go-crypto/openpgp"
|
|
)
|
|
|
|
func convertImportResult(el openpgp.EntityList, err error) (EntityList, error) {
|
|
if err != nil {
|
|
return EntityList{}, err
|
|
}
|
|
result := EntityList{
|
|
EntityList: el,
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func ReadArmoredKeyRingBinary(data []byte) (EntityList, error) {
|
|
r := bytes.NewReader(data)
|
|
return convertImportResult(openpgp.ReadArmoredKeyRing(r))
|
|
}
|
|
|
|
func ReadKeyRingBinary(data []byte) (EntityList, error) {
|
|
r := bytes.NewReader(data)
|
|
return convertImportResult(openpgp.ReadKeyRing(r))
|
|
}
|
|
|
|
func ReadArmoredKeyRingFromFile(filepath string) (EntityList, error) {
|
|
file, err := os.Open(filepath)
|
|
if err != nil {
|
|
return EntityList{}, err
|
|
}
|
|
defer file.Close()
|
|
return convertImportResult(openpgp.ReadArmoredKeyRing(file))
|
|
}
|
|
|
|
func ReadKeyRingFromFile(filepath string) (EntityList, error) {
|
|
file, err := os.Open(filepath)
|
|
if err != nil {
|
|
return EntityList{}, err
|
|
}
|
|
defer file.Close()
|
|
return convertImportResult(openpgp.ReadKeyRing(file))
|
|
}
|