mirror of
https://github.com/dolthub/dolt.git
synced 2025-12-30 16:12:39 -06:00
signature in log (should be optional)
This commit is contained in:
@@ -676,8 +676,8 @@ func getCommitInfo(queryist cli.Queryist, sqlCtx *sql.Context, ref string) (*Com
|
||||
isHead := commitHash == hashOfHead
|
||||
|
||||
var signature string
|
||||
if len(row) > 6 {
|
||||
signature = row[6].(string)
|
||||
if len(row) > 7 {
|
||||
signature = row[7].(string)
|
||||
}
|
||||
|
||||
localBranchesForHash, err := getBranchesForHash(queryist, sqlCtx, commitHash, true)
|
||||
|
||||
@@ -749,7 +749,7 @@ func (itr *logTableFunctionRowIter) Next(ctx *sql.Context) (sql.Row, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
row := sql.NewRow(commitHash.String(), meta.Name, meta.Email, meta.Time(), meta.Description, meta.Signature)
|
||||
row := sql.NewRow(commitHash.String(), meta.Name, meta.Email, meta.Time(), meta.Description)
|
||||
|
||||
if itr.showParents {
|
||||
prStr, err := getParentsString(ctx, commit)
|
||||
@@ -765,6 +765,8 @@ func (itr *logTableFunctionRowIter) Next(ctx *sql.Context) (sql.Row, error) {
|
||||
row = row.Append(sql.NewRow(getRefsString(branchNames, isHead)))
|
||||
}
|
||||
|
||||
row = row.Append(sql.NewRow(meta.Signature))
|
||||
|
||||
return row, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
package dprocedures
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
@@ -201,13 +200,12 @@ func doDoltCommit(ctx *sql.Context, args []string) (string, bool, error) {
|
||||
return "", false, err
|
||||
}
|
||||
|
||||
signed, signature, err := gpgSign(ctx, keyId, []byte(strToSign))
|
||||
signature, err := gpg.Sign(ctx, keyId, []byte(strToSign))
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
|
||||
fmt.Println(signed, signature)
|
||||
pendingCommit.CommitOptions.Meta.Signature = signature
|
||||
pendingCommit.CommitOptions.Meta.Signature = string(signature)
|
||||
}
|
||||
|
||||
newCommit, err := dSess.DoltCommit(ctx, dbName, dSess.GetTransaction(), pendingCommit)
|
||||
@@ -267,24 +265,3 @@ func commitSignatureStr(ctx *sql.Context, dbName string, roots doltdb.Roots, csp
|
||||
|
||||
return strings.Join(lines, "\n"), nil
|
||||
}
|
||||
|
||||
func gpgSign(ctx context.Context, keyId string, toSign []byte) (string, string, error) {
|
||||
blocks, err := gpg.Sign(ctx, keyId, toSign)
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("failed to sign: %w", err)
|
||||
}
|
||||
|
||||
signedDataBlocks := gpg.GetBlocksOfType(blocks, "PGP SIGNED MESSAGE")
|
||||
|
||||
if len(signedDataBlocks) != 1 {
|
||||
return "", "", fmt.Errorf("expected 1 'PGP SIGNED MESSAGE' block, got %d", len(signedDataBlocks))
|
||||
}
|
||||
|
||||
signatureBlocks := gpg.GetBlocksOfType(blocks, "PGP SIGNATURE")
|
||||
|
||||
if len(signatureBlocks) != 1 {
|
||||
return "", "", fmt.Errorf("expected 1 PGP SIGNATURE block, got %d", len(signatureBlocks))
|
||||
}
|
||||
|
||||
return string(signedDataBlocks[0].Bytes), string(signatureBlocks[0].Bytes), nil
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Sign(ctx context.Context, keyId string, message []byte) ([]*pem.Block, error) {
|
||||
func Sign(ctx context.Context, keyId string, message []byte) ([]byte, error) {
|
||||
args := []string{"--clear-sign", "-u", keyId}
|
||||
cmdStr := fmt.Sprintf("gpg %s", strings.Join(args, " "))
|
||||
cmd := exec.CommandContext(ctx, "gpg", args...)
|
||||
@@ -72,12 +72,7 @@ func Sign(ctx context.Context, keyId string, message []byte) ([]*pem.Block, erro
|
||||
return nil, fmt.Errorf("failed to read output for command '%s': %w", cmdStr, err)
|
||||
}
|
||||
|
||||
pemBlocks, err := decodeAllPEMBlocks(outBuf.Bytes())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to decode PEM blocks: %w", err)
|
||||
}
|
||||
|
||||
return pemBlocks, nil
|
||||
return outBuf.Bytes(), nil
|
||||
}
|
||||
|
||||
func listenToOut(ctx context.Context, eg *errgroup.Group, r io.Reader) *bytes.Buffer {
|
||||
@@ -90,7 +85,7 @@ func listenToOut(ctx context.Context, eg *errgroup.Group, r io.Reader) *bytes.Bu
|
||||
}
|
||||
|
||||
// Throws away all intersperesed text and returns all decoded PEM blocks, in the order they are read.
|
||||
func decodeAllPEMBlocks(bs []byte) ([]*pem.Block, error) {
|
||||
func DecodeAllPEMBlocks(bs []byte) ([]*pem.Block, error) {
|
||||
const beginHeaderPrefix = "BEGIN "
|
||||
const pemSeperator = "-----"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user