aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_commit.go
diff options
context:
space:
mode:
authorPaulo Gomes <pjbgf@linux.com>2024-02-21 10:48:14 +0000
committerGitHub <noreply@github.com>2024-02-21 10:48:14 +0000
commit686a0f7a492894fc3efd67e8be99a4240b9b65ec (patch)
treeaa4dbdbe05982b274b4eca55f3f8e991889b9d28 /worktree_commit.go
parent6f46f8c0bd6397a0c827235c8106ce0799b24923 (diff)
parent9fa13d83c6e473d0aca7b97a620b3f4a003993f6 (diff)
downloadgo-git-686a0f7a492894fc3efd67e8be99a4240b9b65ec.tar.gz
Merge pull request #1029 from wlynch/signer-fix
Signer: fix usage of crypto.Signer interface
Diffstat (limited to 'worktree_commit.go')
-rw-r--r--worktree_commit.go37
1 files changed, 4 insertions, 33 deletions
diff --git a/worktree_commit.go b/worktree_commit.go
index 18002f2..7945af1 100644
--- a/worktree_commit.go
+++ b/worktree_commit.go
@@ -2,8 +2,6 @@ package git
import (
"bytes"
- "crypto"
- "crypto/rand"
"errors"
"io"
"path"
@@ -135,7 +133,7 @@ func (w *Worktree) buildCommitObject(msg string, opts *CommitOptions, tree plumb
signer = &gpgSigner{key: opts.SignKey}
}
if signer != nil {
- sig, err := w.buildCommitSignature(commit, signer)
+ sig, err := signObject(signer, commit)
if err != nil {
return plumbing.ZeroHash, err
}
@@ -151,44 +149,17 @@ func (w *Worktree) buildCommitObject(msg string, opts *CommitOptions, tree plumb
type gpgSigner struct {
key *openpgp.Entity
+ cfg *packet.Config
}
-func (s *gpgSigner) Public() crypto.PublicKey {
- return s.key.PrimaryKey
-}
-
-func (s *gpgSigner) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error) {
- var cfg *packet.Config
- if opts != nil {
- cfg = &packet.Config{
- DefaultHash: opts.HashFunc(),
- }
- }
-
+func (s *gpgSigner) Sign(message io.Reader) ([]byte, error) {
var b bytes.Buffer
- if err := openpgp.ArmoredDetachSign(&b, s.key, bytes.NewReader(digest), cfg); err != nil {
+ if err := openpgp.ArmoredDetachSign(&b, s.key, message, s.cfg); err != nil {
return nil, err
}
return b.Bytes(), nil
}
-func (w *Worktree) buildCommitSignature(commit *object.Commit, signer crypto.Signer) ([]byte, error) {
- encoded := &plumbing.MemoryObject{}
- if err := commit.Encode(encoded); err != nil {
- return nil, err
- }
- r, err := encoded.Reader()
- if err != nil {
- return nil, err
- }
- b, err := io.ReadAll(r)
- if err != nil {
- return nil, err
- }
-
- return signer.Sign(rand.Reader, b, nil)
-}
-
// buildTreeHelper converts a given index.Index file into multiple git objects
// reading the blobs from the given filesystem and creating the trees from the
// index structure. The created objects are pushed to a given Storer.