Refactor setup
This commit is contained in:
parent
94b317f135
commit
0456595f68
25 changed files with 37 additions and 33 deletions
33
src/gitlab.com/ProtonMail/go-pm-crypto/key/fingerprint.go
Normal file
33
src/gitlab.com/ProtonMail/go-pm-crypto/key/fingerprint.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package key
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
|
||||
"golang.org/x/crypto/openpgp"
|
||||
"gitlab.com/ProtonMail/go-pm-crypto/armor"
|
||||
)
|
||||
|
||||
// GetFingerprint get a armored public key fingerprint
|
||||
func GetFingerprint(publicKey string) (string, error) {
|
||||
rawPubKey, err := armor.Unarmor(publicKey)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return GetFingerprintBinKey(rawPubKey)
|
||||
}
|
||||
|
||||
// GetFingerprintBinKey get a unarmored public key fingerprint
|
||||
func GetFingerprintBinKey(publicKey []byte) (string, error) {
|
||||
pubKeyReader := bytes.NewReader(publicKey)
|
||||
pubKeyEntries, err := openpgp.ReadKeyRing(pubKeyReader)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
for _, e := range pubKeyEntries {
|
||||
fp := e.PrimaryKey.Fingerprint
|
||||
return hex.EncodeToString(fp[:]), nil
|
||||
}
|
||||
return "", errors.New("Can't find public key")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue