From fe29f9c134ab272e9f47d9643bd3916e025f2ba1 Mon Sep 17 00:00:00 2001 From: Richard Jennings Date: Thu, 11 Jan 2024 19:25:23 +0000 Subject: [PATCH] read pgp signature --- internal/mygit/objects/object.go | 1 + internal/mygit/objects/reader.go | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/internal/mygit/objects/object.go b/internal/mygit/objects/object.go index 88120bc..18cb8fc 100644 --- a/internal/mygit/objects/object.go +++ b/internal/mygit/objects/object.go @@ -28,6 +28,7 @@ type ( Committer string CommitterEmail string CommittedTime time.Time + Sig []byte Message []byte } Tree struct { diff --git a/internal/mygit/objects/reader.go b/internal/mygit/objects/reader.go index 8519772..5a3b28a 100644 --- a/internal/mygit/objects/reader.go +++ b/internal/mygit/objects/reader.go @@ -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() { @@ -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