summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-08-21 07:50:15 +0100
committerGitHub <noreply@github.com>2022-08-21 02:50:15 -0400
commit11bae504846293806fec27f3271e0d3aba8f0f93 (patch)
treeb2e0356c8c442c336f0dfca497cce9bb22a57395 /models
parent0ee96da052edd3fe25b66d2c9fd5fd3d01171091 (diff)
downloadgitea-11bae504846293806fec27f3271e0d3aba8f0f93.tar.gz
gitea-11bae504846293806fec27f3271e0d3aba8f0f93.zip
Pad GPG Key ID with preceding zeroes (#20878)
Diffstat (limited to 'models')
-rw-r--r--models/asymkey/gpg_key.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/models/asymkey/gpg_key.go b/models/asymkey/gpg_key.go
index 2b99972379..21554d2150 100644
--- a/models/asymkey/gpg_key.go
+++ b/models/asymkey/gpg_key.go
@@ -63,6 +63,15 @@ func (key *GPGKey) AfterLoad(session *xorm.Session) {
}
}
+// PaddedKeyID show KeyID padded to 16 characters
+func (key *GPGKey) PaddedKeyID() string {
+ if len(key.KeyID) > 15 {
+ return key.KeyID
+ }
+ zeros := "0000000000000000"
+ return zeros[0:16-len(key.KeyID)] + key.KeyID
+}
+
// ListGPGKeys returns a list of public keys belongs to given user.
func ListGPGKeys(ctx context.Context, uid int64, listOptions db.ListOptions) ([]*GPGKey, error) {
sess := db.GetEngine(ctx).Table(&GPGKey{}).Where("owner_id=? AND primary_key_id=''", uid)