loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix missing 0 prefix of GPG key id (#30245)

Fixes #30235

If the key id "front" byte has a single digit, `%X` is missing the 0
prefix.
` 38D1A3EADDBEA9C` instead of
`038D1A3EADDBEA9C`
When using the `IssuerFingerprint` slice `%X` is enough but I changed it
to `%016X` too to be consistent.

(cherry picked from commit eb505b128c7b9b2459f2a5d20b5740017125178b)

Conflicts:
- models/asymkey/gpg_key_commit_verification.go
Ported the change to models/asymkey/gpg_key_object_verification.go

authored by

KN4CK3R and committed by
Gergely Nagy
63904e2f 0b27b962

+23 -7
+10
models/asymkey/gpg_key_common.go
··· 134 134 } 135 135 return sig, nil 136 136 } 137 + 138 + func tryGetKeyIDFromSignature(sig *packet.Signature) string { 139 + if sig.IssuerKeyId != nil && (*sig.IssuerKeyId) != 0 { 140 + return fmt.Sprintf("%016X", *sig.IssuerKeyId) 141 + } 142 + if sig.IssuerFingerprint != nil && len(sig.IssuerFingerprint) > 0 { 143 + return fmt.Sprintf("%016X", sig.IssuerFingerprint[12:20]) 144 + } 145 + return "" 146 + }
+1 -7
models/asymkey/gpg_key_object_verification.go
··· 123 123 } 124 124 } 125 125 126 - keyID := "" 127 - if sig.IssuerKeyId != nil && (*sig.IssuerKeyId) != 0 { 128 - keyID = fmt.Sprintf("%X", *sig.IssuerKeyId) 129 - } 130 - if keyID == "" && sig.IssuerFingerprint != nil && len(sig.IssuerFingerprint) > 0 { 131 - keyID = fmt.Sprintf("%X", sig.IssuerFingerprint[12:20]) 132 - } 126 + keyID := tryGetKeyIDFromSignature(sig) 133 127 defaultReason := NoKeyFound 134 128 135 129 // First check if the sig has a keyID and if so just look at that
+12
models/asymkey/gpg_key_test.go
··· 11 11 "code.gitea.io/gitea/models/unittest" 12 12 user_model "code.gitea.io/gitea/models/user" 13 13 "code.gitea.io/gitea/modules/timeutil" 14 + "code.gitea.io/gitea/modules/util" 14 15 16 + "github.com/keybase/go-crypto/openpgp/packet" 15 17 "github.com/stretchr/testify/assert" 16 18 ) 17 19 ··· 391 393 assert.Equal(t, time.Unix(1586105389, 0), expire) 392 394 } 393 395 } 396 + 397 + func TestTryGetKeyIDFromSignature(t *testing.T) { 398 + assert.Empty(t, tryGetKeyIDFromSignature(&packet.Signature{})) 399 + assert.Equal(t, "038D1A3EADDBEA9C", tryGetKeyIDFromSignature(&packet.Signature{ 400 + IssuerKeyId: util.ToPointer(uint64(0x38D1A3EADDBEA9C)), 401 + })) 402 + assert.Equal(t, "038D1A3EADDBEA9C", tryGetKeyIDFromSignature(&packet.Signature{ 403 + IssuerFingerprint: []uint8{0xb, 0x23, 0x24, 0xc7, 0xe6, 0xfe, 0x4f, 0x3a, 0x6, 0x26, 0xc1, 0x21, 0x3, 0x8d, 0x1a, 0x3e, 0xad, 0xdb, 0xea, 0x9c}, 404 + })) 405 + }