Back to godoc.org

Package pubkeyhash

v0.2.2
Latest Go to latest

The latest major version is .

Published: May 30, 2020 | License: Apache-2.0 | Module: github.com/IPA-CyberLab/kmgm

Index

Variables

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
	},
}

type FormatType

type FormatType int
const (
	FormatFull FormatType = iota
	FormatHashOnly
)

func FormatTypeFromString

func FormatTypeFromString(s string) (FormatType, error)

func (FormatType) ShouldOutputLabel

func (ft FormatType) ShouldOutputLabel() bool

type KeyHash

type KeyHash struct {
	Label string
	Hash  string
}

func ExtractPublicKeyHashesFromPem

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

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier