36 lines
534 B
Go
36 lines
534 B
Go
|
package git
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
|
||
|
"github.com/ProtonMail/go-crypto/openpgp"
|
||
|
"github.com/ProtonMail/go-crypto/openpgp/armor"
|
||
|
)
|
||
|
|
||
|
type SignKey struct {
|
||
|
KeyFile string
|
||
|
|
||
|
entity *openpgp.Entity
|
||
|
}
|
||
|
|
||
|
func (s *SignKey) ReadKeyFile() error {
|
||
|
file, err := os.Open(s.KeyFile)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer file.Close()
|
||
|
|
||
|
block, err := armor.Decode(file)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
entityList, err := openpgp.ReadKeyRing(block.Body)
|
||
|
if err != nil || len(entityList) < 1 {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
s.entity = entityList[0]
|
||
|
return nil
|
||
|
}
|