Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sign.go « git2goutil « gitaly-git2go « cmd - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: efa8d1b1d76351dc2cd8465edc87eef0eccc46b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package git2goutil

import (
	"fmt"

	"gitlab.com/gitlab-org/gitaly/v16/internal/signature"
)

// CreateCommitSignature reads the given signing key and produces PKCS#7 detached signature.
// When the path to the signing key is not present, an empty signature is returned.
func CreateCommitSignature(signingKeyPath string, contentToSign []byte) ([]byte, error) {
	if signingKeyPath == "" {
		return nil, nil
	}

	signingKeys, err := signature.ParseSigningKeys(signingKeyPath)
	if err != nil {
		return nil, fmt.Errorf("failed to parse signing key: %w", err)
	}

	return signingKeys.CreateSignature(contentToSign)
}