Add SHA256 fingerprint utils and helpers (#41)
This commit is contained in:
parent
c8b7e87135
commit
3c79f40acb
8 changed files with 88 additions and 3 deletions
|
|
@ -46,3 +46,12 @@ func GenerateKey(name, email string, passphrase []byte, keyType string, bits int
|
|||
key.ClearPrivateParams()
|
||||
return locked.Armor()
|
||||
}
|
||||
|
||||
func GetSHA256Fingerprints(publicKey string) ([]string, error) {
|
||||
key, err := crypto.NewKeyFromArmored(publicKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return key.GetSHA256Fingerprints(), nil
|
||||
}
|
||||
|
|
|
|||
18
helper/key_test.go
Normal file
18
helper/key_test.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package helper
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetSHA256FingerprintsV4(t *testing.T) {
|
||||
sha256Fingerprints, err := GetSHA256Fingerprints(readTestFile("keyring_publicKey", false))
|
||||
if err != nil {
|
||||
t.Fatal("Cannot unarmor key:", err)
|
||||
}
|
||||
|
||||
assert.Len(t, sha256Fingerprints, 2)
|
||||
assert.Exactly(t, "d9ac0b857da6d2c8be985b251a9e3db31e7a1d2d832d1f07ebe838a9edce9c24", sha256Fingerprints[0])
|
||||
assert.Exactly(t, "203dfba1f8442c17e59214d9cd11985bfc5cc8721bb4a71740dd5507e58a1a0d", sha256Fingerprints[1])
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
package helper
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||
)
|
||||
|
||||
|
|
@ -65,3 +67,12 @@ func EncryptAttachment(plainData []byte, fileName string, keyRing *crypto.KeyRin
|
|||
}
|
||||
return decrypted, nil
|
||||
}
|
||||
|
||||
func GetJsonSHA256Fingerprints(publicKey string) ([]byte, error) {
|
||||
key, err := crypto.NewKeyFromArmored(publicKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return json.Marshal(key.GetSHA256Fingerprints())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,3 +53,12 @@ func TestMobileSignedMessageDecryption(t *testing.T) {
|
|||
assert.NotNil(t, err)
|
||||
assert.Nil(t, decrypted)
|
||||
}
|
||||
|
||||
func TestGetJsonSHA256FingerprintsV4(t *testing.T) {
|
||||
sha256Fingerprints, err := GetJsonSHA256Fingerprints(readTestFile("keyring_publicKey", false))
|
||||
if err != nil {
|
||||
t.Fatal("Cannot unarmor key:", err)
|
||||
}
|
||||
|
||||
assert.Exactly(t, []byte("[\"d9ac0b857da6d2c8be985b251a9e3db31e7a1d2d832d1f07ebe838a9edce9c24\",\"203dfba1f8442c17e59214d9cd11985bfc5cc8721bb4a71740dd5507e58a1a0d\"]"), sha256Fingerprints)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue