Exemplo n.º 1
0
import (
	"fmt"

	"github.com/MYOB-Technology/pops/lib"
	"github.com/spf13/cobra"
)

var flagRandIvSize int
var flagRandIvBase64 bool

var randIvCmd = &cobra.Command{
	Use:   "iv",
	Short: "Create a random iv",
	Long:  `Create a random iv. Print to STDOUT`,
	Run: func(cmd *cobra.Command, args []string) {
		b := lib.RandomBytes(flagRandIvSize)
		if flagRandIvBase64 {
			fmt.Println(lib.EncodeBase64(b))
		} else {
			fmt.Println(string(b))
		}
	},
}

func init() {
	RandCmd.AddCommand(randIvCmd)
	randIvCmd.Flags().IntVar(&flagRandIvSize, "size", 16, "Size of the iv")
	randIvCmd.Flags().BoolVar(&flagRandIvBase64, "base64", true, "Whether to encode output in base64")
}
Exemplo n.º 2
0
	"github.com/MYOB-Technology/pops/lib"
	"github.com/spf13/cobra"
)

var flagRandSecretSize int
var flagRandSecretBase64 bool
var flagRandSecretNewLine bool

var randSecretCmd = &cobra.Command{
	Use:   "secret",
	Short: "Create a random secret",
	Long: `Create a random secret. Print to STDOUT.
  If you pipe to a file, we recommend you to chmod the file to 400`,
	Run: func(cmd *cobra.Command, args []string) {
		b := lib.RandomBytes(flagRandSecretSize)
		if flagRandSecretBase64 {
			fmt.Print(lib.EncodeBase64(b))
		} else {
			fmt.Print(string(b))
		}
		if flagRandSecretNewLine {
			fmt.Println()
		}
	},
}

func init() {
	RandCmd.AddCommand(randSecretCmd)
	randSecretCmd.Flags().IntVar(&flagRandSecretSize, "size", 512, "Size of the secret")
	randSecretCmd.Flags().BoolVar(&flagRandSecretBase64, "base64", true, "Whether to encode output in base64")