1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
// Package pgp provides interface to signature generation and validation
package pgp
import (
"fmt"
"io"
"os"
)
// Key is key in PGP representation
type Key string
// Matches checks two keys for equality
func (key1 Key) Matches(key2 Key) bool {
if key1 == key2 {
return true
}
if len(key1) == 8 && len(key2) == 16 {
return key1 == key2[8:]
}
if len(key1) == 16 && len(key2) == 8 {
return key1[8:] == key2
}
return false
}
// KeyFromUint64 converts openpgp uint64 into hex human-readable
func KeyFromUint64(key uint64) Key {
return Key(fmt.Sprintf("%016X", key))
}
// KeyInfo is response from signature verification
type KeyInfo struct {
GoodKeys []Key
MissingKeys []Key
}
// Signer interface describes facility implementing signing of files
type Signer interface {
Init() error
SetKey(keyRef string)
SetKeyRing(keyring, secretKeyring string)
SetPassphrase(passphrase, passphraseFile string)
SetBatch(batch bool)
DetachedSign(source string, destination string) error
ClearSign(source string, destination string) error
}
// Verifier interface describes signature verification factility
type Verifier interface {
InitKeyring(verbose bool) error
AddKeyring(keyring string)
VerifyDetachedSignature(signature, cleartext io.Reader, showKeyTip bool) error
IsClearSigned(clearsigned io.Reader) (bool, error)
VerifyClearsigned(clearsigned io.Reader, showKeyTip bool) (*KeyInfo, error)
ExtractClearsigned(clearsigned io.Reader) (text *os.File, err error)
}
|