Skip to content

Commit 30af2e4

Browse files
authored
Merge pull request #269 from ProtonMail/fix/v6-key-id-pub
Fix: PublicKey.KeyIdString must return a valid key id PublicKey.KeyIdString() previously did not compute the key ID correctly for v5 and v6 keys. This PR fixes the issue by directly using the stored key ID from the struct.
2 parents d703f49 + f621215 commit 30af2e4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

openpgp/packet/public_key.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -1048,12 +1048,17 @@ func (pk *PublicKey) VerifyDirectKeySignature(sig *Signature) (err error) {
10481048
// KeyIdString returns the public key's fingerprint in capital hex
10491049
// (e.g. "6C7EE1B8621CC013").
10501050
func (pk *PublicKey) KeyIdString() string {
1051-
return fmt.Sprintf("%X", pk.Fingerprint[12:20])
1051+
return fmt.Sprintf("%016X", pk.KeyId)
10521052
}
10531053

10541054
// KeyIdShortString returns the short form of public key's fingerprint
10551055
// in capital hex, as shown by gpg --list-keys (e.g. "621CC013").
1056+
// This function will return the full key id for v5 and v6 keys
1057+
// since the short key id is undefined for them.
10561058
func (pk *PublicKey) KeyIdShortString() string {
1059+
if pk.Version >= 5 {
1060+
return pk.KeyIdString()
1061+
}
10571062
return fmt.Sprintf("%X", pk.Fingerprint[16:20])
10581063
}
10591064

0 commit comments

Comments
 (0)