forked from gopasspw/gopass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
public_key.go
38 lines (31 loc) · 833 Bytes
/
public_key.go
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
package keyring
import (
"encoding/binary"
"fmt"
"time"
"golang.org/x/crypto/sha3"
"github.com/justwatchcom/gopass/pkg/backend/crypto/xc/xcpb"
)
// PublicKeyAlgorithm is a type of public key algorithm
type PublicKeyAlgorithm uint8
const (
// PubKeyNaCl is a NaCl (Salt) based public key
PubKeyNaCl PublicKeyAlgorithm = iota
)
// PublicKey is the public part of a keypair
type PublicKey struct {
CreationTime time.Time
PubKeyAlgo PublicKeyAlgorithm
PublicKey [32]byte
Identity *xcpb.Identity
}
// Fingerprint calculates the unique ID of a public key
func (p PublicKey) Fingerprint() string {
h := make([]byte, 20)
d := sha3.NewShake256()
_, _ = d.Write([]byte{0x42})
_ = binary.Write(d, binary.LittleEndian, p.PubKeyAlgo)
_, _ = d.Write(p.PublicKey[:])
_, _ = d.Read(h)
return fmt.Sprintf("%x", h)
}