Merge pull request #5 from euphoria-laxis/release/v2.1.0
Some checks failed
Test github.com/euphoria-laxis/argon2 / build (push) Has been cancelled
Some checks failed
Test github.com/euphoria-laxis/argon2 / build (push) Has been cancelled
Remove useless options for decoder
This commit is contained in:
commit
8c8fb8c6b9
|
@ -36,7 +36,7 @@ func TestEncoder(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDecoder(t *testing.T) {
|
func TestDecoder(t *testing.T) {
|
||||||
decoder, _ := NewDecoder(opts...)
|
decoder := NewDecoder()
|
||||||
match, err := decoder.CompareStringToHash(randomString, hashedString)
|
match, err := decoder.CompareStringToHash(randomString, hashedString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
|
|
|
@ -8,20 +8,13 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Decoder struct {
|
type Decoder struct{}
|
||||||
Options
|
|
||||||
|
func NewDecoder() *Decoder {
|
||||||
|
return new(Decoder)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDecoder(opts ...OptFunc) (*Decoder, *Options) {
|
func (decoder *Decoder) decodeHash(encodedHash string) (o *Options, salt, hash []byte, err error) {
|
||||||
o := defaultOptions
|
|
||||||
for _, fn := range opts {
|
|
||||||
fn(&o)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &Decoder{o}, &o
|
|
||||||
}
|
|
||||||
|
|
||||||
func (decoder *Decoder) decodeHash(encodedHash string) (d *Decoder, salt, hash []byte, err error) {
|
|
||||||
values := strings.Split(encodedHash, "$")
|
values := strings.Split(encodedHash, "$")
|
||||||
if len(values) != 6 {
|
if len(values) != 6 {
|
||||||
return nil, nil, nil, ErrInvalidHash
|
return nil, nil, nil, ErrInvalidHash
|
||||||
|
@ -34,7 +27,8 @@ func (decoder *Decoder) decodeHash(encodedHash string) (d *Decoder, salt, hash [
|
||||||
if version != argon2.Version {
|
if version != argon2.Version {
|
||||||
return nil, nil, nil, ErrIncompatibleVersion
|
return nil, nil, nil, ErrIncompatibleVersion
|
||||||
}
|
}
|
||||||
_, err = fmt.Sscanf(values[3], "m=%d,t=%d,p=%d", &decoder.Memory, &decoder.Iterations, &decoder.Parallelism)
|
o = new(Options)
|
||||||
|
_, err = fmt.Sscanf(values[3], "m=%d,t=%d,p=%d", &o.Memory, &o.Iterations, &o.Parallelism)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -42,15 +36,15 @@ func (decoder *Decoder) decodeHash(encodedHash string) (d *Decoder, salt, hash [
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
d = decoder
|
o.SaltLength = uint32(len(salt))
|
||||||
d.SaltLength = uint32(len(salt))
|
|
||||||
hash, err = base64.RawStdEncoding.DecodeString(values[5])
|
hash, err = base64.RawStdEncoding.DecodeString(values[5])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
d.KeyLength = uint32(len(hash))
|
o.KeyLength = uint32(len(hash))
|
||||||
|
|
||||||
return d, salt, hash, nil
|
return o, salt, hash, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (decoder *Decoder) CompareStringToHash(password string, hashedPassword string) (match bool, err error) {
|
func (decoder *Decoder) CompareStringToHash(password string, hashedPassword string) (match bool, err error) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user