stubbed out
This commit is contained in:
99
pwgenerator/funcs_genopts.go
Normal file
99
pwgenerator/funcs_genopts.go
Normal file
@@ -0,0 +1,99 @@
|
||||
package pwgenerator
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Generate generates a list of passwords for a GenOpts.
|
||||
func (o *GenOpts) Generate() (passwords []string, err error) {
|
||||
|
||||
// TODO
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Chars returns the list of evaluated characters that would be used in a GenOpts.
|
||||
func (o *GenOpts) Chars() (chars CharSet) {
|
||||
|
||||
chars = make(CharSet, 0)
|
||||
|
||||
if o.explicitCharset != nil && len(o.explicitCharset) != 0 {
|
||||
chars = o.explicitCharset
|
||||
return
|
||||
}
|
||||
|
||||
if o.Alpha {
|
||||
chars = append(chars, alpha...)
|
||||
}
|
||||
if o.Numeric {
|
||||
chars = append(chars, numeric...)
|
||||
}
|
||||
if o.Symbols {
|
||||
chars = append(chars, symbols...)
|
||||
}
|
||||
if o.ExtendedSymbols {
|
||||
chars = append(chars, extendedSymbols...)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
SetExplicitCharset sets a GenOpts' charset to an explicit selection. It is deduplicated before being used unless inclDupes is true.
|
||||
(Duplicate runes can be used to increase the likelihood of specific characters.)
|
||||
|
||||
Note that if an explicit charset is defined, the following opts will have NO effect:
|
||||
|
||||
Alpha
|
||||
Numeric
|
||||
Symbols
|
||||
ExtendedSymbols
|
||||
CountUpper
|
||||
CountLower
|
||||
CountSymbols
|
||||
CountExtended
|
||||
DisabledChars
|
||||
|
||||
To have these fields be used again, call GenOpts.UnsetExplicitCharset.
|
||||
|
||||
chars can be a CharSet, []rune, []byte, []string, or string
|
||||
*/
|
||||
func (o *GenOpts) SetExplicitCharset(chars interface{}, inclDupes bool) (err error) {
|
||||
|
||||
var charset CharSet
|
||||
|
||||
switch t := chars.(type) {
|
||||
case []rune:
|
||||
charset = CharSet(string(t))
|
||||
case []byte:
|
||||
charset = CharSet(string(t))
|
||||
case []string:
|
||||
s := strings.Join(t, "")
|
||||
charset = CharSet(s)
|
||||
case string:
|
||||
charset = CharSet(t)
|
||||
default:
|
||||
err = ErrBadType
|
||||
return
|
||||
}
|
||||
|
||||
if !inclDupes {
|
||||
sortDedupe(&charset)
|
||||
}
|
||||
|
||||
o.explicitCharset = charset
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
UnsetExplicitCharset removes the explicit charset used for generation and instead uses the fields specified in the actual GenOpts.
|
||||
|
||||
See GenOpts.SetExplicitCharset for more details.
|
||||
*/
|
||||
func (o *GenOpts) UnsetExplicitCharset() {
|
||||
|
||||
o.explicitCharset = nil
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user