<commit_before>package main

import (
	"flag"
	"fmt"
	"os"
	"os/user"
	"path/filepath"

	"github.com/ssh-vault/crypto"
	"github.com/ssh-vault/crypto/aead"
	sv "github.com/ssh-vault/ssh-vault"
)

var version string

func exit1(err error) {
	fmt.Println(err)
	os.Exit(1)
}

func main() {
	var (
		k       = flag.String("k", "~/.ssh/id_rsa.pub", "Public `ssh key or index` when using option -u")
		u       = flag.String("u", "", "GitHub `username or URL`, optional [-k N] where N is the key index to use")
		f       = flag.Bool("f", false, "Print ssh key `fingerprint`")
		options = []string{"create", "edit", "view"}
		v       = flag.Bool("v", false, fmt.Sprintf("Print version: %s", version))
	)

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: %s [-k key] [-u user] [create|edit|view] vault\n\n%s\n%s\n%s\n%s\n\n",
			os.Args[0],
			"  Options:",
			"    create    Creates a new vault",
			"    edit      Edit an existing vault",
			"    view      View an existing vault")
		flag.PrintDefaults()
	}

	flag.Parse()

	if *v {
		fmt.Printf("%s\n", version)
		os.Exit(0)
	}

	usr, _ := user.Current()
	if len(*k) > 2 {
		if (*k)[:2] == "~/" {
			*k = filepath.Join(usr.HomeDir, (*k)[2:])
		}
	}

	vault, err := sv.New(*k, *u, flag.Arg(0), flag.Arg(1))
	if err != nil {
		exit1(fmt.Errorf("%s, use (\"%s -h\") for help.\n", os.Args[0]))
	}

	// ssh-keygen -f id_rsa.pub -e -m PKCS8
	if err := vault.PKCS8(); err != nil {
		exit1(fmt.Errorf("%s, use (\"%s -h\") for help.\n", os.Args[0]))
	}

	// print fingerprint and exit
	if *f {
		fmt.Println(vault.Fingerprint)
		os.Exit(0)
	}

	if flag.NArg() < 1 {
		exit1(fmt.Errorf("Missing option, use (\"%s -h\") for help.\n", os.Args[0]))
	}
	// check options
	exit := true
	for _, v := range options {
		if flag.Arg(0) == v {
			exit = false
			break
		}
	}
	if exit {
		exit1(fmt.Errorf("Invalid option, use (\"%s -h\") for help.\n", os.Args[0]))
	}

	// check for vault name
	if flag.NArg() < 2 {
		exit1(fmt.Errorf("Missing vault name, use (\"%s -h\") for help.\n", os.Args[0]))
	}

	vault.Password, err = crypto.GenerateNonce(32)
	if err != nil {<commit_msg>	modified:   cmd/ssh-vault/main.go<commit_after>package main

import (
	"flag"
	"fmt"
	"os"
	"os/user"
	"path/filepath"

	"github.com/ssh-vault/crypto"
	"github.com/ssh-vault/crypto/aead"
	sv "github.com/ssh-vault/ssh-vault"
)

var version string

func exit1(err error) {
	fmt.Println(err)
	os.Exit(1)
}

func main() {
	var (
		k       = flag.String("k", "~/.ssh/id_rsa.pub", "Public `ssh key or index` when using option -u")
		u       = flag.String("u", "", "GitHub `username or URL`, optional [-k N] where N is the key index to use")
		f       = flag.Bool("f", false, "Print ssh key `fingerprint`")
		options = []string{"create", "edit", "view"}
		v       = flag.Bool("v", false, fmt.Sprintf("Print version: %s", version))
	)

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: %s [-k key] [-u user] [create|edit|view] vault\n\n%s\n%s\n%s\n%s\n\n",
			os.Args[0],
			"  Options:",
			"    create    Creates a new vault",
			"    edit      Edit an existing vault",
			"    view      View an existing vault")
		flag.PrintDefaults()
	}

	flag.Parse()

	if *v {
		fmt.Printf("%s\n", version)
		os.Exit(0)
	}

	if flag.NArg() < 1 && !*f {
		exit1(fmt.Errorf("Missing option, use (\"%s -h\") for help.\n", os.Args[0]))
	}

	usr, _ := user.Current()
	if len(*k) > 2 {
		if (*k)[:2] == "~/" {
			*k = filepath.Join(usr.HomeDir, (*k)[2:])
		}
	}

	vault, err := sv.New(*k, *u, flag.Arg(0), flag.Arg(1))
	if err != nil {
		exit1(err)
	}

	// ssh-keygen -f id_rsa.pub -e -m PKCS8
	if err := vault.PKCS8(); err != nil {
		exit1(err)
	}

	// print fingerprint and exit
	if *f {
		fmt.Println(vault.Fingerprint)
		os.Exit(0)
	}

	// check options
	exit := true
	for _, v := range options {
		if flag.Arg(0) == v {
			exit = false
			break
		}
	}
	if exit {
		exit1(fmt.Errorf("Invalid option, use (\"%s -h\") for help.\n", os.Args[0]))
	}

	// check for vault name
	if flag.NArg() < 2 {
		exit1(fmt.Errorf("Missing vault name, use (\"%s -h\") for help.\n", os.Args[0]))
	}

	vault.Password, err = crypto.GenerateNonce(32)
	if err != nil {
{'fraction_non_alphanumeric': 0.2079207920792079, 'fraction_numerical': 0.012557353296305241, 'mean_word_length': 2.7586206896551726, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '196061', 'n_tokens_mistral': 1850, 'n_tokens_neox': 1731, 'n_words': 419}