gpg

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package gpg provides a GPG-based object signer for creating armored detached signatures using OpenPGP keys.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrNilSigner is returned when the key provided is nil.
	ErrNilSigner = errors.New("signer is nil")
	// ErrNilMessage is returned when a nil message is passed to Sign.
	ErrNilMessage = errors.New("message is nil")
)

Sentinel errors.

Functions

func FromKey

func FromKey(key *openpgp.Entity) (*signer, error)

FromKey creates a new GPG signer that uses the provided OpenPGP entity to produce armored detached signatures.

Example
package main

import (
	"fmt"
	"strings"

	"github.com/ProtonMail/go-crypto/openpgp"

	"github.com/go-git/x/plugin/objectsigner/gpg"
)

func main() {
	// Generate a test key. In practice this would be read from an armored file.
	key, err := openpgp.NewEntity("Test User", "", "test@example.com", nil)
	if err != nil {
		panic(err)
	}

	signer, err := gpg.FromKey(key)
	if err != nil {
		panic(err)
	}

	sig, err := signer.Sign(strings.NewReader("signed commit message\n"))
	if err != nil {
		panic(err)
	}

	fmt.Println(strings.Contains(string(sig), "-----BEGIN PGP SIGNATURE-----"))
	fmt.Println(strings.Contains(string(sig), "-----END PGP SIGNATURE-----"))
}
Output:
true
true

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL