cmd

package
v0.0.0-...-767fa57 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ClientCmd = &cobra.Command{
	Use:     "client {-c endpoint|-l endpoint} [flags] [args]",
	Run:     handler.ClientMain,
	Args:    cobra.ArbitraryArgs,
	PreRunE: handler.CheckClientFlags,
}
View Source
var DevCmd = &cobra.Command{
	Use: "dev",
	Run: func(cmd *cobra.Command, args []string) {
		logger.Print("error:", devMain(cmd, args))
	},
}

DevCmd represents the test command

View Source
var KeygenCmd = &cobra.Command{
	Use:   "keygen [paths]",
	Short: "Generate med key pairs",
	Run: func(cmd *cobra.Command, args []string) {
		_, _ = cmd, args

		if len(args) == 0 {
			publicKey, privateKey, err := ed25519.GenerateKey(rand.Reader)
			if err != nil {
				panic(err)
			}
			fmt.Printf("key = %s\n", hex.EncodeToString(privateKey))
			fmt.Printf("pub = %s\n", hex.EncodeToString(publicKey))

			return
		}

		for i, path := range args {
			pub, key, err := ed25519.GenerateKey(rand.Reader)
			if err != nil {
				panic(err)
			}

			{
				keyPath := fmt.Sprintf("%s.key", path)
				data := hex.EncodeToString(key) + "\n"
				err := os.WriteFile(keyPath, []byte(data), 0600)
				if err != nil {
					fmt.Println("error:", err)
					return
				}
				fmt.Printf("key[%d] = %s\n", i, keyPath)
			}

			{
				pubPath := fmt.Sprintf("%s.pub", path)
				data := hex.EncodeToString(pub) + "\n"
				err := os.WriteFile(pubPath, []byte(data), 0622)
				if err != nil {
					fmt.Printf("pub[%d] = %s\n", i, pubPath)
					return
				}
				fmt.Printf("pub[%d] = %s\n", i, pubPath)
			}
		}
	},
}
View Source
var ServerCmd = &cobra.Command{
	Use:     "server {-c endpoint|-l endpoint}",
	Short:   "Start a med server",
	Run:     handler.ServerMain,
	PreRunE: handler.CheckServerFlags,
}

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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