Skip to content

Commit

Permalink
read pgp signature
Browse files Browse the repository at this point in the history
  • Loading branch information
richardjennings committed Jan 11, 2024
1 parent bce1292 commit fe29f9c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions internal/mygit/objects/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type (
Committer string
CommitterEmail string
CommittedTime time.Time
Sig []byte
Message []byte
}
Tree struct {
Expand Down
20 changes: 19 additions & 1 deletion internal/mygit/objects/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ func readCommit(obj *Object) (*Commit, error) {
c := &Commit{Sha: obj.Sha}

s := bufio.NewScanner(r)
gpgsig := false

for {
if !s.Scan() {
Expand Down Expand Up @@ -247,11 +248,28 @@ func readCommit(obj *Object) (*Commit, error) {
}
// can be GPG Signature
if t == "gpgsig" {
// currently not implementing @todo implement signed commits
gpgsig = true
continue
}
if gpgsig {
if len(p[1]) == 0 {
continue
}
// @todo build up signature lines
if string(p[1]) != "-----END PGP SIGNATURE-----" {
c.Sig = append(c.Sig, l...)
c.Sig = append(c.Sig, []byte("\n")...)
continue
}
gpgsig = false
continue
}
if len(c.Message) == 0 && len(l) < 2 {
continue
}
// now we have the message body hopefully
c.Message = append(c.Message, l...)
c.Message = append(c.Message, []byte("\n")...)
}

return c, nil
Expand Down

0 comments on commit fe29f9c

Please sign in to comment.