aboutsummaryrefslogtreecommitdiffstats
path: root/signer.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 /signer.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 'signer.go')
-rw-r--r--signer.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/signer.go b/signer.go
new file mode 100644
index 0000000..e3ef7eb
--- /dev/null
+++ b/signer.go
@@ -0,0 +1,33 @@
+package git
+
+import (
+ "io"
+
+ "github.com/go-git/go-git/v5/plumbing"
+)
+
+// signableObject is an object which can be signed.
+type signableObject interface {
+ EncodeWithoutSignature(o plumbing.EncodedObject) error
+}
+
+// Signer is an interface for signing git objects.
+// message is a reader containing the encoded object to be signed.
+// Implementors should return the encoded signature and an error if any.
+// See https://git-scm.com/docs/gitformat-signature for more information.
+type Signer interface {
+ Sign(message io.Reader) ([]byte, error)
+}
+
+func signObject(signer Signer, obj signableObject) ([]byte, error) {
+ encoded := &plumbing.MemoryObject{}
+ if err := obj.EncodeWithoutSignature(encoded); err != nil {
+ return nil, err
+ }
+ r, err := encoded.Reader()
+ if err != nil {
+ return nil, err
+ }
+
+ return signer.Sign(r)
+}