gnupg

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDirLookupFailed   = errors.New("failed to lookup gpg directories")
	ErrInvalidTrustLevel = errors.New("invlaid key owner trust level")
	ErrGetKeygripsFailed = errors.New("failed to get keygrips")
)
View Source
var (
	ErrPrimaryIdentityNotFound = errors.New("no primary identity found")
	ErrReadKeyFailed           = errors.New("failed to read private key")
)

Functions

func IsArmored

func IsArmored(key string) bool

IsArmored checks if the given key is armored by trying to parse it. Returns true if the key is armored, false otherwise.

Types

type Client

type Client struct {
	Homedir string
	Env     []string
	Key     Key
	Version Version
	Dirs    Dirs
}

func New

func New(key, passphrase string) (*Client, error)

New creates a new Client instance with the given private key and passphrase.

func (*Client) Cleanup

func (c *Client) Cleanup() error

Cleanup removes the home directory for the given key, if one was specified. It returns any error encountered while removing the directory.

func (*Client) GetDirs

func (c *Client) GetDirs() error

GetDirs queries gpgconf to get the GnuPG directory paths and populates the Dirs struct with the results. It parses the gpgconf output to extract the lib, libexec, data and home dirs.

func (*Client) GetVersion

func (c *Client) GetVersion() (*Version, error)

GetVersion queries gpg to get the version information and populates the Version struct with the results.

func (*Client) ImportKey

func (c *Client) ImportKey() error

ImportKey imports a GPG key provided via the Key.Content field. It runs the gpg --import command to import the key into the keyring. Returns an error if the import command fails.

func (*Client) ReadPrivateKey

func (c *Client) ReadPrivateKey() error

ReadPrivateKey reads a private key from the given Key struct. It parses the armored key content into a gopenpgp private key. It returns the key ID, creation time, identity, and fingerprint. It returns an error if the key could not be parsed or the primary identity was not found.

func (*Client) SetHomedir

func (c *Client) SetHomedir(path string) error

SetHomedir sets the home directory path for the GPG client. It creates the directory if it doesn't exist and sets the GNUPGHOME environment variable to point to it.

func (*Client) SetTrustLevel

func (c *Client) SetTrustLevel(level string) error

SetTrustLevel sets the trust level for the public key in the client. It runs the gpg --edit-key command to set the trust level to the provided level string. Valid levels are "unknown", "never", "marginal", "full", "ultimate". Returns an error if the command fails.

func (*Client) SignFile

func (c *Client) SignFile(armor, detach, clear bool, path string) error

SignFile signs the file at the given path with the configured key. It supports detached, cleartext, and normal signing based on the detach and clear arguments.

type Dirs

type Dirs struct {
	Lib     string
	Libexec string
	Data    string
	Home    string
}

type Key

type Key struct {
	Content    string
	Passphrase string

	ID           string
	Fingerprint  string
	Identity     string
	CreationTime time.Time
}

type Version

type Version struct {
	Gnupg     string
	Libgcrypt string
}

Jump to

Keyboard shortcuts

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