Documentation ¶
Index ¶
- Variables
- func Register(def ...Definition)
- func Set(pwd string) error
- func SetDefault(def Definition)
- type Crypter
- type Definition
- type Factory
- func (c *Factory) CrypterFound() Crypter
- func (c *Factory) FlagHelper() string
- func (p *Factory) MarshalText() ([]byte, error)
- func (c *Factory) Register(def ...Definition)
- func (c *Factory) Set(pwd string) error
- func (c *Factory) SetDefault(def Definition)
- func (c *Factory) String() string
- func (p *Factory) UnmarshalText(text []byte) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
Types ¶
type Crypter ¶
type Crypter interface { Salt(salt []byte) Crypter Hashed(pwd []byte) Crypter Crypt(pwd []byte) Crypter Verify(pwd []byte) bool Options() map[string]interface{} Definition() Definition encoding.TextMarshaler flag.Value }
func CrypterFound ¶
func CrypterFound() Crypter
type Definition ¶
type Definition interface { String() string CrypterFound(string) (Crypter, bool) Options() map[string]interface{} Default() Crypter SetOptions(map[string]interface{}) Definition Crypt(pwd, salt []byte, options map[string]interface{}) string }
var APR1 Definition = md5driver{apr1_prefix}
var BCRYPT Definition = register(bcryptdriver{bcrypt_prefix[0], bcrypt_def_cost})
var MD5 Definition = md5driver{md5_prefix}
var SHA256 Definition = register(sha256driver{sha256_def_rounds})
var SHA512 Definition = register(sha512driver{sha512_def_rounds})
type Factory ¶
type Factory struct { CustomFlagHelper func([]string) string // contains filtered or unexported fields }
Example ¶
fs := flag.NewFlagSet("", flag.ExitOnError) fact := &Factory{ CustomFlagHelper: func(d []string) string { return "type of password accepted : " + strings.Join(d, ", ") }, } fact.Register(SHA256, SHA512, BCRYPT) fs.SetOutput(os.Stdout) fs.Var(fact, "password", fact.FlagHelper()) fs.PrintDefaults() fs.Parse([]string{"-password=$2a$06$DCq7YPn5Rq63x1Lad4cll.TV4S6ytwfsfvkgY8jIucDrjc8deX1s."}) crypter := fact.CrypterFound() fmt.Printf("this password is %s\n", crypter.Definition().String())
Output: -password value type of password accepted : {SHA256-CRYPT}, {SHA512-CRYPT}, {BLF-CRYPT} this password is {BLF-CRYPT}
func (*Factory) CrypterFound ¶
func (*Factory) FlagHelper ¶
func (*Factory) MarshalText ¶
func (*Factory) Register ¶
func (c *Factory) Register(def ...Definition)
func (*Factory) SetDefault ¶
func (c *Factory) SetDefault(def Definition)
func (*Factory) UnmarshalText ¶
Example ¶
var t struct { Password *Factory `json:"pwd"` } data := []byte(`{"pwd":"$2a$06$DCq7YPn5Rq63x1Lad4cll.TV4S6ytwfsfvkgY8jIucDrjc8deX1s."}`) if err := json.Unmarshal(data, &t); err != nil { log.Fatal(err) } if t.Password == nil { log.Fatal("no password parsed") } crypter := t.Password.CrypterFound() if crypter == nil { log.Fatal("no password found") } fmt.Printf("the password in json %s is a %v\n", data, crypter.Definition())
Output: the password in json {"pwd":"$2a$06$DCq7YPn5Rq63x1Lad4cll.TV4S6ytwfsfvkgY8jIucDrjc8deX1s."} is a {BLF-CRYPT}
Source Files ¶
Click to show internal directories.
Click to hide internal directories.