File: pgp.go

package info (click to toggle)
aptly 1.6.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 49,928 kB
  • sloc: python: 10,398; sh: 252; makefile: 184
file content (60 lines) | stat: -rw-r--r-- 1,491 bytes parent folder | download | duplicates (3)
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)
}