<commit_before>package handlers

import (
	"crypto/rand"
	"encoding/hex"
	"flag"
	"fmt"
	"github.com/FactomProject/cli"
	ed "github.com/FactomProject/ed25519"
	"github.com/FactomProject/serveridentity/functions"
	"github.com/FactomProject/serveridentity/identity"
	"io"
	"os"
)

var SCRIPTNAME string = "fullidentity"
var PRINT_OUT bool = true

/*
 * This file is only used for testing purposes
 */

var Full = func() *sevCmd {
	identity.ShowBruteForce = PRINT_OUT
	cmd := new(sevCmd)
	cmd.helpMsg = "serveridentity full 'fresh'|ESAddress|elements"
	cmd.description = "Create new identity and subchain as well as entries in the subchain."
	cmd.execFunc = func(args []string) {
		os.Args = args
		flag.Parse()
		args = flag.Args()
		c := cli.New()
		c.HandleFunc("elements", elementsFull)
		c.HandleFunc("fresh", freshFull)
		c.HandleDefaultFunc(existingECFull)
		c.HandleFunc("help", func(args []string) {
			fmt.Println(cmd.helpMsg)
		})
		c.Execute(args)
	}
	Help.Add("Create a full Identity", cmd)
	return cmd
}()

func existingECFull(args []string) {
	if len(args) == 0 {
		Help.All()
		return
	}
	os.Args = args
	filename := flag.String("n", "fullidentity", "Change the script name")
	flag.Parse()
	SCRIPTNAME = *filename
	l := len(args[0])
	if l != 64 && l != 52 {
		fmt.Println("serveridentity full 'fresh'|ESAddress")
		fmt.Println("Invalid ES Address entered, exiting program...")
		return
	} else if l == 52 {
		// Generate all new Keys from EC
		sid := generateKeysFromEC(args[0], PRINT_OUT)
		if sid == nil {
			return
		}
		fullStart(sid)
	} else if l == 64 {
		fmt.Println("Only base58 human readable key accepted.")
	}
}

func freshFull(args []string) {
	os.Args = args
	filename := flag.String("n", "fullidentity", "Change the script name")
	flag.Parse()
	SCRIPTNAME = *filename
	// Generate all new Keys
	sid := generateKeys(PRINT_OUT)
	if sid == nil {
		return
	}
	fullStart(sid)
}

func elementsFull(args []string) {
	os.Args = args
	filename := flag.String("n", "fullidentity", "Change the script name")
	flag.Parse()
	SCRIPTNAME = *filename
	var sid *functions.ServerIdentity

	if len(args) > 1 {
		fmt.Println(args[1])
		l := len(args[1])
		if l != 52 {
			fmt.Println("serveridentity full elements ESAddress")
			fmt.Println("Invalid ES Address entered, exiting program...")
			return
		} else {
			// Generate all new Keys from EC
			sid = generateKeysFromEC(args[1], PRINT_OUT)
			if sid == nil {
				return
			}
		}
	} else {
		sid = generateKeysFromEC("<KEY>", PRINT_OUT)
		if sid == nil {
			return
		}
	}
	fullStartElements(sid)
}

func fullStart(sid *functions.ServerIdentity) {
	file = makeFile(SCRIPTNAME)<commit_msg>Fixed flag to name script file<commit_after>package handlers

import (
	"crypto/rand"
	"encoding/hex"
	"flag"
	"fmt"
	"github.com/FactomProject/cli"
	ed "github.com/FactomProject/ed25519"
	"github.com/FactomProject/serveridentity/functions"
	"github.com/FactomProject/serveridentity/identity"
	"io"
	"os"
)

var SCRIPTNAME string = "fullidentity"
var PRINT_OUT bool = true

/*
 * This file is only used for testing purposes
 */

var Full = func() *sevCmd {
	identity.ShowBruteForce = PRINT_OUT
	cmd := new(sevCmd)
	cmd.helpMsg = "serveridentity full 'fresh'|ESAddress|elements"
	cmd.description = "Create new identity and subchain as well as entries in the subchain."
	cmd.execFunc = func(args []string) {
		os.Args = args
		flag.Parse()
		args = flag.Args()
		c := cli.New()
		c.HandleFunc("elements", elementsFull)
		c.HandleFunc("fresh", freshFull)
		c.HandleDefaultFunc(existingECFull)
		c.HandleFunc("help", func(args []string) {
			fmt.Println(cmd.helpMsg)
		})
		c.Execute(args)
	}
	Help.Add("Create a full Identity", cmd)
	return cmd
}()

func existingECFull(args []string) {
	if len(args) == 0 {
		Help.All()
		return
	}
	os.Args = args
	filename := flag.String("n", "fullidentity", "Change the script name")
	flag.Parse()
	SCRIPTNAME = *filename
	l := len(args[0])
	if l != 64 && l != 52 {
		fmt.Println("serveridentity full 'fresh'|ESAddress")
		fmt.Println("Invalid ES Address entered, exiting program...")
		return
	} else if l == 52 {
		// Generate all new Keys from EC
		sid := generateKeysFromEC(args[0], PRINT_OUT)
		if sid == nil {
			return
		}
		fullStart(sid)
	} else if l == 64 {
		fmt.Println("Only base58 human readable key accepted.")
	}
}

func freshFull(args []string) {
	os.Args = args
	filename := flag.String("n", "fullidentity", "Change the script name")
	flag.Parse()
	SCRIPTNAME = *filename
	// Generate all new Keys
	sid := generateKeys(PRINT_OUT)
	if sid == nil {
		return
	}
	fullStart(sid)
}

func elementsFull(args []string) {
	if len(args) > 1 {
		os.Args = args[1:]
	} else {
		os.Args = args
	}
	filename := flag.String("n", "fullidentity", "Change the script name")
	flag.Parse()
	SCRIPTNAME = *filename
	var sid *functions.ServerIdentity

	if len(args) > 1 {
		fmt.Println(args[1])
		l := len(args[1])
		if l != 52 {
			fmt.Println("serveridentity full elements ESAddress")
			fmt.Println("Invalid ES Address entered, exiting program...")
			return
		} else {
			// Generate all new Keys from EC
			sid = generateKeysFromEC(args[1], PRINT_OUT)
			if sid == nil {
				return
			}
		}
	} else {
		sid = generateKeysFromEC("<KEY>", PRINT_OUT)
		if sid == nil {
			return
		}
	}
	fullStartElements(sid)
}

func fullStart(sid *functions.ServerIdentity) {
	file = makeFile(SCRIPTNAME)
{'fraction_non_alphanumeric': 0.14078212290502792, 'fraction_numerical': 0.00931098696461825, 'mean_word_length': 3.8518518518518516, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '6047979', 'n_tokens_mistral': 2068, 'n_tokens_neox': 1886, 'n_words': 488}