forked from toolshed/abra
chore: vendor
This commit is contained in:
30
vendor/github.com/decentral1se/passgen/.gitignore
generated
vendored
Normal file
30
vendor/github.com/decentral1se/passgen/.gitignore
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
.DS_Store
|
||||
*.[56789ao]
|
||||
*.a[56789o]
|
||||
*.so
|
||||
._*
|
||||
.nfs.*
|
||||
[56789a].out
|
||||
*~
|
||||
*.orig
|
||||
*.rej
|
||||
*.exe
|
||||
.*.swp
|
||||
core
|
||||
*.cgo*.go
|
||||
*.cgo*.c
|
||||
_cgo_*
|
||||
_obj
|
||||
_test
|
||||
_testmain.go
|
||||
|
||||
/VERSION.cache
|
||||
/bin/
|
||||
/build.out
|
||||
/goinstall.log
|
||||
/last-change
|
||||
/test.out
|
||||
/dist
|
||||
/cover
|
||||
/prof
|
||||
/passgen.test
|
13
vendor/github.com/decentral1se/passgen/LICENSE
generated
vendored
Normal file
13
vendor/github.com/decentral1se/passgen/LICENSE
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
Copyright (c) 2020 Matt Schultz <matt@schultz.is>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any purpose
|
||||
with or without fee is hereby granted, provided that the above copyright notice
|
||||
and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
61
vendor/github.com/decentral1se/passgen/Makefile
generated
vendored
Normal file
61
vendor/github.com/decentral1se/passgen/Makefile
generated
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
VERSION ?= $(shell git describe --tags --dirty --match 'v*.*.*')
|
||||
|
||||
.PHONY: build
|
||||
build:
|
||||
mkdir -p dist
|
||||
go build \
|
||||
-v \
|
||||
-race \
|
||||
-mod vendor \
|
||||
-o dist \
|
||||
-ldflags "-X main.version=$(VERSION)" \
|
||||
./cmd/...
|
||||
|
||||
.PHONY: install
|
||||
install:
|
||||
go install \
|
||||
-v \
|
||||
-race \
|
||||
-mod vendor \
|
||||
-ldflags "-X main.version=$(VERSION)" \
|
||||
./cmd/...
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -rf dist
|
||||
rm -rf cover
|
||||
rm -rf prof
|
||||
rm -rf passgen.test
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
mkdir -p cover
|
||||
go test \
|
||||
-v \
|
||||
-race \
|
||||
-coverprofile cover/cover.out \
|
||||
./...
|
||||
|
||||
.PHONY: cover
|
||||
cover:
|
||||
go tool cover \
|
||||
-html \
|
||||
cover/cover.out
|
||||
|
||||
.PHONY: vet
|
||||
vet:
|
||||
go vet -v ./...
|
||||
|
||||
.PHONY: lint
|
||||
lint:
|
||||
golangci-lint run -v ./...
|
||||
|
||||
.PHONY: benchmark
|
||||
benchmark:
|
||||
mkdir -p prof
|
||||
go test \
|
||||
-v \
|
||||
-run Benchmark \
|
||||
-cpuprofile prof/cpu.prof \
|
||||
-memprofile prof/mem.prof \
|
||||
-bench ./...
|
3
vendor/github.com/decentral1se/passgen/README.md
generated
vendored
Normal file
3
vendor/github.com/decentral1se/passgen/README.md
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# passgen
|
||||
|
||||
Resurrected fork of the original `schultz-is/passgen` which is nowhere to be found on the internet now.
|
7836
vendor/github.com/decentral1se/passgen/const.go
generated
vendored
Normal file
7836
vendor/github.com/decentral1se/passgen/const.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
135
vendor/github.com/decentral1se/passgen/passphrase.go
generated
vendored
Normal file
135
vendor/github.com/decentral1se/passgen/passphrase.go
generated
vendored
Normal file
@ -0,0 +1,135 @@
|
||||
package passgen
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// PassphraseCasing represents the casing of each word within a passphrase.
|
||||
type PassphraseCasing uint8
|
||||
|
||||
// GeneratePassphrases generates random passphrases based on the configuration provided by the user.
|
||||
func GeneratePassphrases(
|
||||
count uint, // Number of passphrases to generate.
|
||||
wordCount uint, // Length, in words, of each generated passphrase.
|
||||
separator rune, // Passphrase word separator.
|
||||
casing PassphraseCasing, // Passphrase word casing.
|
||||
wordList []string, // List of words to pull passphrase words from.
|
||||
) (
|
||||
passphrases []string, // Generated passphrases.
|
||||
err error, // Possible error encountered during passphrase generation.
|
||||
) {
|
||||
// Validate the supplied count parameter.
|
||||
if count < PassphraseCountMin || count > PassphraseCountMax {
|
||||
return nil, fmt.Errorf("count must be at least %d and at most %d", PassphraseCountMin, PassphraseCountMax)
|
||||
}
|
||||
|
||||
// Validate the supplied word count parameter.
|
||||
if wordCount < PassphraseWordCountMin || wordCount > PassphraseWordCountMax {
|
||||
return nil, fmt.Errorf("word count must be at least %d and at most %d", PassphraseWordCountMin, PassphraseWordCountMax)
|
||||
}
|
||||
|
||||
// Validate the supplied casing parameter.
|
||||
switch casing {
|
||||
case PassphraseCasingLower, PassphraseCasingUpper, PassphraseCasingTitle, PassphraseCasingNone:
|
||||
break
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid word casing")
|
||||
}
|
||||
|
||||
// Deduplicate the provided word list.
|
||||
words := map[string]struct{}{}
|
||||
for _, word := range wordList {
|
||||
switch casing {
|
||||
case PassphraseCasingLower:
|
||||
words[strings.ToLower(word)] = struct{}{}
|
||||
case PassphraseCasingUpper:
|
||||
words[strings.ToUpper(word)] = struct{}{}
|
||||
case PassphraseCasingTitle:
|
||||
words[strings.Title(word)] = struct{}{}
|
||||
case PassphraseCasingNone:
|
||||
words[word] = struct{}{}
|
||||
}
|
||||
}
|
||||
var wordSet []string
|
||||
for word := range words {
|
||||
wordSet = append(wordSet, word)
|
||||
}
|
||||
|
||||
// Validate the provided word list.
|
||||
if len(wordSet) < WordListLengthMin {
|
||||
return nil, fmt.Errorf("word list must contain at least %d unique words", WordListLengthMin)
|
||||
}
|
||||
|
||||
// Determine how many bytes are needed to represent a passphrase of the specified word count in
|
||||
// the provided word list.
|
||||
bitsPerWord := uint(math.Ceil(math.Log2(float64(len(wordSet)))))
|
||||
bitsPerPassphrase := bitsPerWord * wordCount
|
||||
bytesPerPassphrase := bitsPerPassphrase / 8
|
||||
if bitsPerPassphrase%8 > 0 {
|
||||
bytesPerPassphrase++
|
||||
}
|
||||
|
||||
var (
|
||||
i uint // Passphrase counter.
|
||||
b strings.Builder // String builder for efficiently constructing passphrases.
|
||||
passphraseBuffer []byte // Byte buffer for random data used as a passphrase source.
|
||||
)
|
||||
|
||||
for i = 0; i < count; i++ {
|
||||
// Read enough random data to sufficiently produce a passphrase.
|
||||
passphraseBuffer = make([]byte, bytesPerPassphrase)
|
||||
_, err = io.ReadFull(randSource, passphraseBuffer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var (
|
||||
j uint // Passphrase word counter.
|
||||
wordIdx uint // Word index within the provided word list.
|
||||
bitIdx uint // Source buffer bit counter.
|
||||
byteIdx uint // Source buffer byte counter.
|
||||
wordBitIdx uint // Passphrase word bit counter.
|
||||
)
|
||||
|
||||
for j = 0; j < wordCount; j++ {
|
||||
for wordBitIdx = 0; wordBitIdx < bitsPerWord; wordBitIdx++ {
|
||||
// Left shift the word index to read the next bit.
|
||||
wordIdx <<= 1
|
||||
|
||||
// Set the bit from the passphrase source in the word index.
|
||||
wordIdx |= uint((passphraseBuffer[byteIdx] & (0x80 >> (bitIdx % 8))) >> (7 - (bitIdx % 8)))
|
||||
|
||||
// Increment the bit counter and, if necessary, the byte counter.
|
||||
bitIdx++
|
||||
if bitIdx%8 == 0 {
|
||||
byteIdx++
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure the word index is within the bounds of the word set.
|
||||
wordIdx = wordIdx % uint(len(wordSet))
|
||||
|
||||
// Retrieve the word from the word set and write it to the passphrase.
|
||||
b.WriteString(wordSet[wordIdx])
|
||||
|
||||
// Write the provided separator if this is not the final word in the passphrase.
|
||||
if j < wordCount-1 {
|
||||
b.WriteRune(separator)
|
||||
}
|
||||
|
||||
// Reset the word index value.
|
||||
wordIdx = 0
|
||||
}
|
||||
|
||||
// Append the passphrase to the return list.
|
||||
passphrases = append(passphrases, b.String())
|
||||
|
||||
// Reset the string builder for the next passphrase.
|
||||
b.Reset()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
108
vendor/github.com/decentral1se/passgen/password.go
generated
vendored
Normal file
108
vendor/github.com/decentral1se/passgen/password.go
generated
vendored
Normal file
@ -0,0 +1,108 @@
|
||||
package passgen
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// GeneratePasswords generates random passwords based on the configuration provided by the user.
|
||||
func GeneratePasswords(
|
||||
count uint, // Number of passwords to generate.
|
||||
length uint, // Length of each generated password.
|
||||
alphabet string, // Alphabet to pull password characters from.
|
||||
) (
|
||||
passwords []string, // Generated passwords.
|
||||
err error, // Possible error encountered during password generation.
|
||||
) {
|
||||
// Validate the supplied count parameter.
|
||||
if count < PasswordCountMin || count > PasswordCountMax {
|
||||
return nil, fmt.Errorf("count must be at least %d and at most %d", PasswordCountMin, PasswordCountMax)
|
||||
}
|
||||
|
||||
// Validate the supplied length parameter.
|
||||
if length < PasswordLengthMin || length > PasswordLengthMax {
|
||||
return nil, fmt.Errorf("length must be at least %d and at most %d", PasswordLengthMin, PasswordLengthMax)
|
||||
}
|
||||
|
||||
// Deduplicate the provided alphabet.
|
||||
chars := map[rune]struct{}{}
|
||||
for _, char := range alphabet {
|
||||
chars[char] = struct{}{}
|
||||
}
|
||||
var charSet []rune
|
||||
for char := range chars {
|
||||
charSet = append(charSet, char)
|
||||
}
|
||||
|
||||
// Validate the provided alphabet.
|
||||
if len(charSet) < AlphabetLengthMin {
|
||||
return nil, fmt.Errorf("alphabet must contain at least %d unique characters", AlphabetLengthMin)
|
||||
}
|
||||
|
||||
// Determine how many bytes are needed to represent a password of the specified length in the
|
||||
// provided alphabet.
|
||||
bitsPerChar := uint(math.Ceil(math.Log2(float64(len(charSet)))))
|
||||
bitsPerPassword := bitsPerChar * length
|
||||
bytesPerPassword := bitsPerPassword / 8
|
||||
if bitsPerPassword%8 > 0 {
|
||||
bytesPerPassword++
|
||||
}
|
||||
|
||||
var (
|
||||
i uint // Password counter.
|
||||
b strings.Builder // String builder for efficiently constructing passwords.
|
||||
passwordBuffer []byte // Byte buffer for random data used as password source.
|
||||
)
|
||||
|
||||
for i = 0; i < count; i++ {
|
||||
// Read enough random data to sufficiently produce a password.
|
||||
passwordBuffer = make([]byte, bytesPerPassword)
|
||||
_, err = io.ReadFull(randSource, passwordBuffer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var (
|
||||
j uint // Password character counter.
|
||||
charIdx uint // Character index within the provided alphabet.
|
||||
bitIdx uint // Source buffer bit counter.
|
||||
byteIdx uint // Source buffer byte counter.
|
||||
charBitIdx uint // Password character bit counter.
|
||||
)
|
||||
|
||||
for j = 0; j < length; j++ {
|
||||
for charBitIdx = 0; charBitIdx < bitsPerChar; charBitIdx++ {
|
||||
// Left shift the character index to read the next bit.
|
||||
charIdx <<= 1
|
||||
|
||||
// Set the bit from the password source in the character index.
|
||||
charIdx |= uint((passwordBuffer[byteIdx] & (0x80 >> (bitIdx % 8))) >> (7 - (bitIdx % 8)))
|
||||
|
||||
// Increment the bit counter and, if necessary, the byte counter.
|
||||
bitIdx++
|
||||
if bitIdx%8 == 0 {
|
||||
byteIdx++
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure the character index is within the bounds of the alphabet.
|
||||
charIdx = charIdx % uint(len(charSet))
|
||||
|
||||
// Retrieve the character from the alphabet and write it to the password.
|
||||
b.WriteRune(charSet[charIdx])
|
||||
|
||||
// Reset character index value.
|
||||
charIdx = 0
|
||||
}
|
||||
|
||||
// Append the password to the return list.
|
||||
passwords = append(passwords, b.String())
|
||||
|
||||
// Reset the string builder for the next password.
|
||||
b.Reset()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user