gpgme

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2024 License: BSD-3-Clause Imports: 8 Imported by: 9

README

GPGME (golang)

Go wrapper for the GPGME library.

This library is intended for use with desktop applications. If you are looking to add OpenPGP support to a server application I suggest you first look at golang.org/x/crypto/openpgp.

Installation

go get -u github.com/proglottis/gpgme

Documentation

Documentation

Overview

Package gpgme provides a Go wrapper for the GPGME library

Index

Constants

View Source
const (
	SeekSet = C.SEEK_SET
	SeekCur = C.SEEK_CUR
	SeekEnd = C.SEEK_END
)

Variables

View Source
var Version string

Functions

func EngineCheckVersion

func EngineCheckVersion(p Protocol) error

func GetDirInfo added in v0.1.4

func GetDirInfo(what string) string

func SetEngineInfo

func SetEngineInfo(proto Protocol, fileName, homeDir string) error

Types

type AssuanDataCallback

type AssuanDataCallback func(data []byte) error

type AssuanInquireCallback

type AssuanInquireCallback func(name, args string) error

type AssuanStatusCallback

type AssuanStatusCallback func(status, args string) error

type Callback

type Callback func(uidHint string, prevWasBad bool, f *os.File) error

Callback is the function that is called when a passphrase is required

type Context

type Context struct {
	Key      *Key
	KeyError error
	// contains filtered or unexported fields
}

func New

func New() (*Context, error)

func (*Context) Armor

func (c *Context) Armor() bool

func (*Context) AssuanSend

func (c *Context) AssuanSend(
	cmd string,
	data AssuanDataCallback,
	inquiry AssuanInquireCallback,
	status AssuanStatusCallback,
) error

AssuanSend sends a raw Assuan command to gpg-agent

func (*Context) Decrypt

func (c *Context) Decrypt(ciphertext, plaintext *Data) error

func (*Context) DecryptVerify

func (c *Context) DecryptVerify(ciphertext, plaintext *Data) error

func (*Context) Encrypt

func (c *Context) Encrypt(recipients []*Key, flags EncryptFlag, plaintext, ciphertext *Data) error

func (*Context) EngineInfo

func (c *Context) EngineInfo() *EngineInfo

func (*Context) Export

func (c *Context) Export(pattern string, mode ExportModeFlags, data *Data) error

func (*Context) GetKey

func (c *Context) GetKey(fingerprint string, secret bool) (*Key, error)

func (*Context) Import

func (c *Context) Import(keyData *Data) (*ImportResult, error)

func (*Context) KeyListEnd

func (c *Context) KeyListEnd() error

func (*Context) KeyListMode

func (c *Context) KeyListMode() KeyListMode

func (*Context) KeyListNext

func (c *Context) KeyListNext() bool

func (*Context) KeyListStart

func (c *Context) KeyListStart(pattern string, secretOnly bool) error

func (*Context) PinEntryMode

func (c *Context) PinEntryMode() PinEntryMode

func (*Context) Protocol

func (c *Context) Protocol() Protocol

func (*Context) Release

func (c *Context) Release()

func (*Context) SetArmor

func (c *Context) SetArmor(yes bool)

func (*Context) SetCallback

func (c *Context) SetCallback(callback Callback) error

func (*Context) SetEngineInfo

func (c *Context) SetEngineInfo(proto Protocol, fileName, homeDir string) error

func (*Context) SetKeyListMode

func (c *Context) SetKeyListMode(m KeyListMode) error

func (*Context) SetPinEntryMode

func (c *Context) SetPinEntryMode(m PinEntryMode) error

func (*Context) SetProtocol

func (c *Context) SetProtocol(p Protocol) error

func (*Context) SetTextMode

func (c *Context) SetTextMode(yes bool)

func (*Context) Sign

func (c *Context) Sign(signers []*Key, plain, sig *Data, mode SigMode) error

func (*Context) TextMode

func (c *Context) TextMode() bool

func (*Context) Verify

func (c *Context) Verify(sig, signedText, plain *Data) (string, []Signature, error)

type Data

type Data struct {
	// contains filtered or unexported fields
}

The Data buffer used to communicate with GPGME

func Decrypt

func Decrypt(r io.Reader) (*Data, error)

func NewData

func NewData() (*Data, error)

NewData returns a new memory based data buffer

func NewDataBytes

func NewDataBytes(b []byte) (*Data, error)

NewDataBytes returns a new memory based data buffer that contains `b` bytes

func NewDataFile

func NewDataFile(f *os.File) (*Data, error)

NewDataFile returns a new file based data buffer

func NewDataReadWriteSeeker

func NewDataReadWriteSeeker(rw io.ReadWriteSeeker) (*Data, error)

NewDataReadWriteSeeker returns a new callback based data buffer

func NewDataReadWriter

func NewDataReadWriter(rw io.ReadWriter) (*Data, error)

NewDataReadWriter returns a new callback based data buffer

func NewDataReader

func NewDataReader(r io.Reader) (*Data, error)

NewDataReader returns a new callback based data buffer

func NewDataWriter

func NewDataWriter(w io.Writer) (*Data, error)

NewDataWriter returns a new callback based data buffer

func (*Data) Close

func (d *Data) Close() error

Close releases any resources associated with the data buffer

func (*Data) Name

func (d *Data) Name() string

Name returns the associated filename if any

func (*Data) Read

func (d *Data) Read(p []byte) (int, error)

func (*Data) Seek

func (d *Data) Seek(offset int64, whence int) (int64, error)

func (*Data) Write

func (d *Data) Write(p []byte) (int, error)

type EncryptFlag

type EncryptFlag uint
const (
	EncryptAlwaysTrust EncryptFlag = C.GPGME_ENCRYPT_ALWAYS_TRUST
	EncryptNoEncryptTo EncryptFlag = C.GPGME_ENCRYPT_NO_ENCRYPT_TO
	EncryptPrepare     EncryptFlag = C.GPGME_ENCRYPT_PREPARE
	EncryptExceptSign  EncryptFlag = C.GPGME_ENCRYPT_EXPECT_SIGN
)

type EngineInfo

type EngineInfo struct {
	// contains filtered or unexported fields
}

func GetEngineInfo

func GetEngineInfo() (*EngineInfo, error)

func (*EngineInfo) FileName

func (e *EngineInfo) FileName() string

func (*EngineInfo) HomeDir

func (e *EngineInfo) HomeDir() string

func (*EngineInfo) Next

func (e *EngineInfo) Next() *EngineInfo

func (*EngineInfo) Protocol

func (e *EngineInfo) Protocol() Protocol

func (*EngineInfo) RequiredVersion

func (e *EngineInfo) RequiredVersion() string

func (*EngineInfo) Version

func (e *EngineInfo) Version() string

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error is a wrapper for GPGME errors

func (Error) Code

func (e Error) Code() ErrorCode

func (Error) Error

func (e Error) Error() string

type ErrorCode

type ErrorCode int
const (
	ErrorNoError ErrorCode = C.GPG_ERR_NO_ERROR
	ErrorEOF     ErrorCode = C.GPG_ERR_EOF
)

type ExportModeFlags

type ExportModeFlags uint

ExportModeFlags defines how keys are exported from Export

const (
	ExportModeExtern  ExportModeFlags = C.GPGME_EXPORT_MODE_EXTERN
	ExportModeMinimal ExportModeFlags = C.GPGME_EXPORT_MODE_MINIMAL
)

type HashAlgo

type HashAlgo int

type ImportResult

type ImportResult struct {
	Considered      int
	NoUserID        int
	Imported        int
	ImportedRSA     int
	Unchanged       int
	NewUserIDs      int
	NewSubKeys      int
	NewSignatures   int
	NewRevocations  int
	SecretRead      int
	SecretImported  int
	SecretUnchanged int
	NotImported     int
	Imports         []ImportStatus
}

type ImportStatus

type ImportStatus struct {
	Fingerprint string
	Result      error
	Status      ImportStatusFlags
}

type ImportStatusFlags

type ImportStatusFlags uint

ImportStatusFlags describes the type of ImportStatus.Status. The C API in gpgme.h simply uses "unsigned".

type Key

type Key struct {
	// contains filtered or unexported fields
}

func FindKeys

func FindKeys(pattern string, secretOnly bool) ([]*Key, error)

func (*Key) CanAuthenticate

func (k *Key) CanAuthenticate() bool

func (*Key) CanCertify

func (k *Key) CanCertify() bool

func (*Key) CanEncrypt

func (k *Key) CanEncrypt() bool

func (*Key) CanSign

func (k *Key) CanSign() bool

func (*Key) ChainID

func (k *Key) ChainID() string

func (*Key) Disabled

func (k *Key) Disabled() bool

func (*Key) Expired

func (k *Key) Expired() bool

func (*Key) Invalid

func (k *Key) Invalid() bool

func (*Key) IsQualified

func (k *Key) IsQualified() bool

func (*Key) IssuerName

func (k *Key) IssuerName() string

func (*Key) IssuerSerial

func (k *Key) IssuerSerial() string

func (*Key) KeyListMode

func (k *Key) KeyListMode() KeyListMode

func (*Key) OwnerTrust

func (k *Key) OwnerTrust() Validity

func (*Key) Protocol

func (k *Key) Protocol() Protocol

func (*Key) Release

func (k *Key) Release()

func (*Key) Revoked

func (k *Key) Revoked() bool

func (*Key) Secret

func (k *Key) Secret() bool

func (*Key) SubKeys

func (k *Key) SubKeys() *SubKey

func (*Key) UserIDs

func (k *Key) UserIDs() *UserID

type KeyListMode

type KeyListMode uint
const (
	KeyListModeLocal        KeyListMode = C.GPGME_KEYLIST_MODE_LOCAL
	KeyListModeExtern       KeyListMode = C.GPGME_KEYLIST_MODE_EXTERN
	KeyListModeSigs         KeyListMode = C.GPGME_KEYLIST_MODE_SIGS
	KeyListModeSigNotations KeyListMode = C.GPGME_KEYLIST_MODE_SIG_NOTATIONS
	KeyListModeEphemeral    KeyListMode = C.GPGME_KEYLIST_MODE_EPHEMERAL
	KeyListModeModeValidate KeyListMode = C.GPGME_KEYLIST_MODE_VALIDATE
)

type Protocol

type Protocol int
const (
	ProtocolOpenPGP  Protocol = C.GPGME_PROTOCOL_OpenPGP
	ProtocolCMS      Protocol = C.GPGME_PROTOCOL_CMS
	ProtocolGPGConf  Protocol = C.GPGME_PROTOCOL_GPGCONF
	ProtocolAssuan   Protocol = C.GPGME_PROTOCOL_ASSUAN
	ProtocolG13      Protocol = C.GPGME_PROTOCOL_G13
	ProtocolUIServer Protocol = C.GPGME_PROTOCOL_UISERVER
	ProtocolDefault  Protocol = C.GPGME_PROTOCOL_DEFAULT
	ProtocolUnknown  Protocol = C.GPGME_PROTOCOL_UNKNOWN
)

type PubkeyAlgo

type PubkeyAlgo int

type SigMode

type SigMode int
const (
	SigModeNormal SigMode = C.GPGME_SIG_MODE_NORMAL
	SigModeDetach SigMode = C.GPGME_SIG_MODE_DETACH
	SigModeClear  SigMode = C.GPGME_SIG_MODE_CLEAR
)

type SigSum

type SigSum int
const (
	SigSumValid      SigSum = C.GPGME_SIGSUM_VALID
	SigSumGreen      SigSum = C.GPGME_SIGSUM_GREEN
	SigSumRed        SigSum = C.GPGME_SIGSUM_RED
	SigSumKeyRevoked SigSum = C.GPGME_SIGSUM_KEY_REVOKED
	SigSumKeyExpired SigSum = C.GPGME_SIGSUM_KEY_EXPIRED
	SigSumSigExpired SigSum = C.GPGME_SIGSUM_SIG_EXPIRED
	SigSumKeyMissing SigSum = C.GPGME_SIGSUM_KEY_MISSING
	SigSumCRLMissing SigSum = C.GPGME_SIGSUM_CRL_MISSING
	SigSumCRLTooOld  SigSum = C.GPGME_SIGSUM_CRL_TOO_OLD
	SigSumBadPolicy  SigSum = C.GPGME_SIGSUM_BAD_POLICY
	SigSumSysError   SigSum = C.GPGME_SIGSUM_SYS_ERROR
)

type Signature

type Signature struct {
	Summary        SigSum
	Fingerprint    string
	Status         error
	Timestamp      time.Time
	ExpTimestamp   time.Time
	WrongKeyUsage  bool
	PKATrust       uint
	ChainModel     bool
	Validity       Validity
	ValidityReason error
	PubkeyAlgo     PubkeyAlgo
	HashAlgo       HashAlgo
}

type SubKey

type SubKey struct {
	// contains filtered or unexported fields
}

func (*SubKey) CardNumber

func (k *SubKey) CardNumber() string

func (*SubKey) Created

func (k *SubKey) Created() time.Time

func (*SubKey) Disabled

func (k *SubKey) Disabled() bool

func (*SubKey) Expired

func (k *SubKey) Expired() bool

func (*SubKey) Expires

func (k *SubKey) Expires() time.Time

func (*SubKey) Fingerprint

func (k *SubKey) Fingerprint() string

func (*SubKey) Invalid

func (k *SubKey) Invalid() bool

func (*SubKey) KeyID

func (k *SubKey) KeyID() string

func (*SubKey) Next

func (k *SubKey) Next() *SubKey

func (*SubKey) Revoked

func (k *SubKey) Revoked() bool

func (*SubKey) Secret

func (k *SubKey) Secret() bool

type UserID

type UserID struct {
	// contains filtered or unexported fields
}

func (*UserID) Comment

func (u *UserID) Comment() string

func (*UserID) Email

func (u *UserID) Email() string

func (*UserID) Invalid

func (u *UserID) Invalid() bool

func (*UserID) Name

func (u *UserID) Name() string

func (*UserID) Next

func (u *UserID) Next() *UserID

func (*UserID) Revoked

func (u *UserID) Revoked() bool

func (*UserID) UID

func (u *UserID) UID() string

func (*UserID) Validity

func (u *UserID) Validity() Validity

type Validity

type Validity int
const (
	ValidityUnknown   Validity = C.GPGME_VALIDITY_UNKNOWN
	ValidityUndefined Validity = C.GPGME_VALIDITY_UNDEFINED
	ValidityNever     Validity = C.GPGME_VALIDITY_NEVER
	ValidityMarginal  Validity = C.GPGME_VALIDITY_MARGINAL
	ValidityFull      Validity = C.GPGME_VALIDITY_FULL
	ValidityUltimate  Validity = C.GPGME_VALIDITY_ULTIMATE
)

Jump to

Keyboard shortcuts

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