aboutsummaryrefslogtreecommitdiff
path: root/cmd/sigsum-debug/pubkey/pubkey.go
blob: 8f3b4675d64c1d4fc3ad1ea23ab648bfd9294bcd (plain)
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
package pubkey

import (
	"crypto/ed25519"
	"fmt"

	"git.sigsum.org/sigsum-go/pkg/hex"
	"git.sigsum.org/sigsum-tools-go/internal/util"
)

func Main(_ []string) error {
	b, err := util.HexFromStdin()
	if err != nil {
		return err
	}
	if len(b) != ed25519.PrivateKeySize {
		return fmt.Errorf("pubkey: invalid key size %d", len(b))
	}

	priv := ed25519.PrivateKey(b)
	pub, ok := priv.Public().(ed25519.PublicKey)
	if !ok {
		return fmt.Errorf("pubkey: must parse as ed25519")
	}

	fmt.Printf("%s\n", hex.Serialize(pub[:]))
	return nil
}