aboutsummaryrefslogtreecommitdiff
path: root/cmd/sigsum/format/format.go
blob: eff7b3ee2221cb42e4bec9a39053fe522bc4984f (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 format

import (
	"fmt"

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

func Main(args []string, policy policy.Policy) error {
	if len(args) != 1 {
		return fmt.Errorf("format: must have one input file")
	}

	preimage, err := util.FileHash(args[0])
	if err != nil {
		return fmt.Errorf("format: preparing checksum: %v", err)
	}
	stm := types.Statement{
		ShardHint: policy.ShardHint(),
		Checksum:  *types.HashFn(preimage[:]),
	}

	fmt.Printf("%s", stm.ToBinary())
	return nil
}