diff --git a/models/asymkey/ssh_key_commit_verification_test.go b/models/asymkey/ssh_key_commit_verification_test.go index e1ed409bd7..320e114b3d 100644 --- a/models/asymkey/ssh_key_commit_verification_test.go +++ b/models/asymkey/ssh_key_commit_verification_test.go @@ -40,7 +40,7 @@ func TestParseCommitWithSSHSignature(t *testing.T) { Committer: &git.Signature{ Email: "non-existent", }, - Signature: &git.CommitGPGSignature{ + Signature: &git.ObjectSignature{ Payload: `tree 2d491b2985a7ff848d5c02748e7ea9f9f7619f9f parent 45b03601635a1f463b81963a4022c7f87ce96ef9 author user2 1699710556 +0100 @@ -67,7 +67,7 @@ AAAAQIMufOuSjZeDUujrkVK4sl7ICa0WwEftas8UAYxx0Thdkiw2qWjR1U1PKfTLm16/w8 Committer: &git.Signature{ Email: "user2@example.com", }, - Signature: &git.CommitGPGSignature{ + Signature: &git.ObjectSignature{ Payload: `tree 853694aae8816094a0d875fee7ea26278dbf5d0f parent c2780d5c313da2a947eae22efd7dacf4213f4e7f author user2 1699707877 +0100 @@ -89,7 +89,7 @@ Add content Committer: &git.Signature{ Email: "user2@example.com", }, - Signature: &git.CommitGPGSignature{ + Signature: &git.ObjectSignature{ Payload: `tree 853694aae8816094a0d875fee7ea26278dbf5d0f parent c2780d5c313da2a947eae22efd7dacf4213f4e7f author user2 1699707877 +0100 @@ -120,7 +120,7 @@ fs9cMpZVM9BfIKNUSO8QY= Committer: &git.Signature{ Email: "user2@noreply.example.com", }, - Signature: &git.CommitGPGSignature{ + Signature: &git.ObjectSignature{ Payload: `tree 4836c7f639f37388bab4050ef5c97bbbd54272fc parent 795be1b0117ea5c65456050bb9fd84744d4fd9c6 author user2 1699709594 +0100 diff --git a/modules/git/commit.go b/modules/git/commit.go index 3140d1f302..c30f1e35e5 100644 --- a/modules/git/commit.go +++ b/modules/git/commit.go @@ -25,18 +25,12 @@ type Commit struct { Author *Signature Committer *Signature CommitMessage string - Signature *CommitGPGSignature + Signature *ObjectSignature Parents []ObjectID // ID strings submoduleCache *ObjectCache } -// CommitGPGSignature represents a git commit signature part. -type CommitGPGSignature struct { - Signature string - Payload string // TODO check if can be reconstruct from the rest of commit information to not have duplicate data -} - // Message returns the commit message. Same as retrieving CommitMessage directly. func (c *Commit) Message() string { return c.CommitMessage diff --git a/modules/git/commit_convert_gogit.go b/modules/git/commit_convert_gogit.go index 819ea0d1db..abf65bf008 100644 --- a/modules/git/commit_convert_gogit.go +++ b/modules/git/commit_convert_gogit.go @@ -13,7 +13,7 @@ import ( "github.com/go-git/go-git/v5/plumbing/object" ) -func convertPGPSignature(c *object.Commit) *CommitGPGSignature { +func convertPGPSignature(c *object.Commit) *ObjectSignature { if c.PGPSignature == "" { return nil } @@ -51,7 +51,7 @@ func convertPGPSignature(c *object.Commit) *CommitGPGSignature { return nil } - return &CommitGPGSignature{ + return &ObjectSignature{ Signature: c.PGPSignature, Payload: w.String(), } diff --git a/modules/git/commit_reader.go b/modules/git/commit_reader.go index 4809d6c7ed..bf7412aa1d 100644 --- a/modules/git/commit_reader.go +++ b/modules/git/commit_reader.go @@ -97,7 +97,7 @@ readLoop: } } commit.CommitMessage = messageSB.String() - commit.Signature = &CommitGPGSignature{ + commit.Signature = &ObjectSignature{ Signature: signatureSB.String(), Payload: payloadSB.String(), } diff --git a/modules/git/object_signature.go b/modules/git/object_signature.go new file mode 100644 index 0000000000..35fa671a9e --- /dev/null +++ b/modules/git/object_signature.go @@ -0,0 +1,11 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Copyright 2019 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package git + +// ObjectSignature represents a git object (commit, tag) signature part. +type ObjectSignature struct { + Signature string + Payload string // TODO check if can be reconstruct from the rest of commit information to not have duplicate data +} diff --git a/modules/git/repo_tag.go b/modules/git/repo_tag.go index eab4ca5a57..638c508e4b 100644 --- a/modules/git/repo_tag.go +++ b/modules/git/repo_tag.go @@ -196,11 +196,11 @@ func parseTagRef(ref map[string]string) (tag *Tag, err error) { } } - // annotated tag with GPG signature + // annotated tag with signature if tag.Type == "tag" && ref["contents:signature"] != "" { payload := fmt.Sprintf("object %s\ntype commit\ntag %s\ntagger %s\n\n%s\n", tag.Object, tag.Name, ref["creator"], strings.TrimSpace(tag.Message)) - tag.Signature = &CommitGPGSignature{ + tag.Signature = &ObjectSignature{ Signature: ref["contents:signature"], Payload: payload, } diff --git a/modules/git/repo_tag_test.go b/modules/git/repo_tag_test.go index 785c3442a7..8f0875c60d 100644 --- a/modules/git/repo_tag_test.go +++ b/modules/git/repo_tag_test.go @@ -315,7 +315,7 @@ qbHDASXl Type: "tag", Tagger: parseSignatureFromCommitLine("Foo Bar 1565789218 +0300"), Message: "Add changelog of v1.9.1 (#7859)\n\n* add changelog of v1.9.1\n* Update CHANGELOG.md", - Signature: &CommitGPGSignature{ + Signature: &ObjectSignature{ Signature: `-----BEGIN PGP SIGNATURE----- aBCGzBAABCgAdFiEEyWRwv/q1Q6IjSv+D4IPOwzt33PoFAmI8jbIACgkQ4IPOwzt3 diff --git a/modules/git/tag.go b/modules/git/tag.go index 66dc9cc08f..1fe4c16b5d 100644 --- a/modules/git/tag.go +++ b/modules/git/tag.go @@ -26,7 +26,7 @@ type Tag struct { Type string Tagger *Signature Message string - Signature *CommitGPGSignature + Signature *ObjectSignature } // Commit return the commit of the tag reference @@ -74,7 +74,7 @@ l: } } - extractTagSignature := func(signatureBeginMark, signatureEndMark string) (bool, *CommitGPGSignature, string) { + extractTagSignature := func(signatureBeginMark, signatureEndMark string) (bool, *ObjectSignature, string) { idx := strings.LastIndex(tag.Message, signatureBeginMark) if idx == -1 { return false, nil, "" @@ -85,7 +85,7 @@ l: return false, nil, "" } - return true, &CommitGPGSignature{ + return true, &ObjectSignature{ Signature: tag.Message[idx+1 : idx+endSigIdx+len(signatureEndMark)], Payload: string(data[:bytes.LastIndex(data, []byte(signatureBeginMark))+1]), }, tag.Message[:idx+1] diff --git a/modules/git/tag_test.go b/modules/git/tag_test.go index d71501929c..79796bbdc2 100644 --- a/modules/git/tag_test.go +++ b/modules/git/tag_test.go @@ -65,7 +65,7 @@ AAAAQKFeTnxi9ssRqSg+sJcmjAgpgoPq1k5SXm306+mJmkPwvhim8f9Gz6uy1AddPmXaD7 Type: "commit", Tagger: &Signature{Name: "Jane Doe", Email: "jane.doe@example.com", When: time.Unix(1709146405, 0)}, Message: "v0\n", - Signature: &CommitGPGSignature{ + Signature: &ObjectSignature{ Signature: `-----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgvD4pK7baygXxoWoVoKjVEc/xZh 6w+1FUn5hypFqJXNAAAAADZ2l0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5