Home

go-spectre @main - refs - log -
-
https://git.jolheiser.com/go-spectre.git
Go implementation for spectre/masterpassword
go-spectre / template.go
- raw
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
package spectre

import (
	"fmt"
	"strings"
)

// Template is a template type
type Template string

const (
	Maximum Template = "Maximum"
	Long    Template = "Long"
	Medium  Template = "Medium"
	Short   Template = "Short"
	Pin     Template = "PIN"
	Name    Template = "Name"
	Phrase  Template = "Phrase"
	Basic   Template = "Basic"
)

// ParseTemplate parses a Template from s
func ParseTemplate(s string) (Template, error) {
	switch strings.ToLower(s) {
	case "maximum", "max":
		return Maximum, nil
	case "long", "l":
		return Long, nil
	case "medium", "med":
		return Medium, nil
	case "short", "sh":
		return Short, nil
	case "pin":
		return Pin, nil
	case "name":
		return Name, nil
	case "phrase":
		return Phrase, nil
	case "basic":
		return Basic, nil
	default:
		return "", fmt.Errorf("unknown Template %q; available [maximum, long, medium, short, pin, name, phrase, basic]", s)
	}
}

var templates = map[Template][]string{
	Maximum: {
		"anoxxxxxxxxxxxxxxxxx",
		"axxxxxxxxxxxxxxxxxno",
	},
	Long: {
		"CvcvnoCvcvCvcv",
		"CvcvCvcvnoCvcv",
		"CvcvCvcvCvcvno",
		"CvccnoCvcvCvcv",
		"CvccCvcvnoCvcv",
		"CvccCvcvCvcvno",
		"CvcvnoCvccCvcv",
		"CvcvCvccnoCvcv",
		"CvcvCvccCvcvno",
		"CvcvnoCvcvCvcc",
		"CvcvCvcvnoCvcc",
		"CvcvCvcvCvccno",
		"CvccnoCvccCvcv",
		"CvccCvccnoCvcv",
		"CvccCvccCvcvno",
		"CvcvnoCvccCvcc",
		"CvcvCvccnoCvcc",
		"CvcvCvccCvccno",
		"CvccnoCvcvCvcc",
		"CvccCvcvnoCvcc",
		"CvccCvcvCvccno",
	},
	Medium: {
		"CvcnoCvc",
		"CvcCvcno",
	},
	Short: {
		"Cvcn",
	},
	Pin: {
		"nnnn",
	},
	Name: {
		"cvccvcvcv",
	},
	Phrase: {
		"cvcc cvc cvccvcv cvc",
		"cvc cvccvcvcv cvcv",
		"cv cvccv cvc cvcvccv",
	},
	Basic: {
		"aaanaaan",
		"aannaaan",
		"aaannaaa",
	},
}

var characters = map[string]string{
	"V": "AEIOU",
	"C": "BCDFGHJKLMNPQRSTVWXYZ",
	"v": "aeiou",
	"c": "bcdfghjklmnpqrstvwxyz",
	"A": "AEIOUBCDFGHJKLMNPQRSTVWXYZ",
	"a": "AEIOUaeiouBCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz",
	"n": "0123456789",
	"o": "@&%?,=[]_:-+*$#!'^~;()/.",
	"x": "AEIOUaeiouBCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz0123456789!@#$%^&*()",
	" ": " ",
}