aboutsummaryrefslogtreecommitdiff
path: root/cmd/sigsum-debug/pubkey.go
blob: f74992aa2086a47463f1286d5165f0142bc8ea79 (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
package main

import (
	"crypto/ed25519"
	"fmt"

	"git.sigsum.org/sigsum-go/pkg/hex"
)

func CmdPubKey() error {
	b, err := decodeHexFromStdin()
	if err != nil {
		return err
	}
	if len(b) != ed25519.PrivateKeySize {
		return fmt.Errorf("invalid private key: size")
	}

	priv := ed25519.PrivateKey(b)
	pub, ok := priv.Public().(ed25519.PublicKey)
	if !ok {
		return fmt.Errorf("failed converting to public key")
	}

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