pubkeyhash

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &cli.Command{
	Name:    "pubkeyhash",
	Usage:   "Dump pubkeyhash of the specified public key/certificate",
	Aliases: []string{"hash"},
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:    "output",
			Aliases: []string{"o"},
			Usage:   "Output format. (full, hashonly)",
			Value:   "full",
		},
		&cli.PathFlag{
			Name:    "file",
			Aliases: []string{"f"},
			Usage:   "PEM file containing public key/certificates",
			Value:   "-",
		},
	},
	Action: func(c *cli.Context) error {
		env := action.GlobalEnvironment

		ftstr := c.String("output")
		ft, err := FormatTypeFromString(ftstr)
		if err != nil {
			return err
		}

		var r io.Reader

		path := c.String("file")
		if path == "-" {
			r = os.Stdin
		} else {
			f, err := os.Open(path)
			if err != nil {
				return err
			}
			defer f.Close()

			r = f
		}

		bs, err := ioutil.ReadAll(r)
		if err != nil {
			return err
		}

		khs, err := ExtractPublicKeyHashesFromPem(bs, env.Logger)
		if err != nil {
			return err
		}

		for _, e := range khs {
			if ft.ShouldOutputLabel() {
				fmt.Printf("# %s\n", e.Label)
			}
			fmt.Printf("%s\n", e.Hash)
		}

		return nil
	},
}

Functions

This section is empty.

Types

type FormatType added in v0.2.2

type FormatType int
const (
	FormatFull FormatType = iota
	FormatHashOnly
)

func FormatTypeFromString added in v0.2.2

func FormatTypeFromString(s string) (FormatType, error)

func (FormatType) ShouldOutputLabel added in v0.2.2

func (ft FormatType) ShouldOutputLabel() bool

type KeyHash added in v0.2.2

type KeyHash struct {
	Label string
	Hash  string
}

func ExtractPublicKeyHashesFromPem added in v0.2.2

func ExtractPublicKeyHashesFromPem(bs []byte, logger *zap.Logger) ([]KeyHash, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL