From b8cd7c483d2b57ee5b2c0976ecf6f3490d737e5c Mon Sep 17 00:00:00 2001 From: euphoria-laxis Date: Wed, 13 Sep 2023 11:44:19 +0200 Subject: [PATCH] Make Options, Encoder and Decoder properties public --- argon2/decoder.go | 8 ++++---- argon2/encoder.go | 16 ++++++++-------- argon2/options.go | 30 +++++++++++++++--------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/argon2/decoder.go b/argon2/decoder.go index dfd52b9..97f1eb8 100644 --- a/argon2/decoder.go +++ b/argon2/decoder.go @@ -34,7 +34,7 @@ func (decoder *Decoder) decodeHash(encodedHash string) (d *Decoder, salt, hash [ if version != argon2.Version { return nil, nil, nil, ErrIncompatibleVersion } - _, err = fmt.Sscanf(values[3], "m=%d,t=%d,p=%d", &decoder.memory, &decoder.iterations, &decoder.parallelism) + _, err = fmt.Sscanf(values[3], "m=%d,t=%d,p=%d", &decoder.Memory, &decoder.Iterations, &decoder.Parallelism) if err != nil { return nil, nil, nil, err } @@ -43,12 +43,12 @@ func (decoder *Decoder) decodeHash(encodedHash string) (d *Decoder, salt, hash [ return nil, nil, nil, err } d = decoder - d.saltLength = uint32(len(salt)) + d.SaltLength = uint32(len(salt)) hash, err = base64.RawStdEncoding.DecodeString(values[5]) if err != nil { return nil, nil, nil, err } - d.keyLength = uint32(len(hash)) + d.KeyLength = uint32(len(hash)) return d, salt, hash, nil } @@ -58,7 +58,7 @@ func (decoder *Decoder) CompareStringToHash(password string, hashedPassword stri if err != nil { return false, err } - otherHash := argon2.IDKey([]byte(password), salt, p.iterations, p.memory, p.parallelism, p.keyLength) + otherHash := argon2.IDKey([]byte(password), salt, p.Iterations, p.Memory, p.Parallelism, p.KeyLength) if subtle.ConstantTimeCompare(hash, otherHash) == 1 { return true, nil } diff --git a/argon2/encoder.go b/argon2/encoder.go index 4d2575e..72bccd6 100644 --- a/argon2/encoder.go +++ b/argon2/encoder.go @@ -31,26 +31,26 @@ func (encoder *Encoder) generateRandomBytes(n uint32) ([]byte, error) { } func (encoder *Encoder) HashString(password string) (encodedHash string, err error) { - salt, err := encoder.generateRandomBytes(encoder.saltLength) + salt, err := encoder.generateRandomBytes(encoder.SaltLength) if err != nil { return "", err } hash := argon2.IDKey( []byte(password), salt, - encoder.iterations, - encoder.memory, - encoder.parallelism, - encoder.keyLength, + encoder.Iterations, + encoder.Memory, + encoder.Parallelism, + encoder.KeyLength, ) b64Salt := base64.RawStdEncoding.EncodeToString(salt) b64Hash := base64.RawStdEncoding.EncodeToString(hash) encodedHash = fmt.Sprintf( "$argon2id$v=%d$m=%d,t=%d,p=%d$%s$%s", argon2.Version, - encoder.memory, - encoder.iterations, - encoder.parallelism, + encoder.Memory, + encoder.Iterations, + encoder.Parallelism, b64Salt, b64Hash, ) diff --git a/argon2/options.go b/argon2/options.go index 675fb39..0dd8c12 100644 --- a/argon2/options.go +++ b/argon2/options.go @@ -3,22 +3,22 @@ package argon2 import "errors" type Options struct { - memory uint32 - iterations uint32 - parallelism uint8 - saltLength uint32 - keyLength uint32 + Memory uint32 + Iterations uint32 + Parallelism uint8 + SaltLength uint32 + KeyLength uint32 } var ( ErrInvalidHash = errors.New("the encoded hash is not in the correct format") ErrIncompatibleVersion = errors.New("incompatible version of argon2") defaultOptions = Options{ - memory: 64 * 1024, - iterations: 3, - parallelism: 2, - saltLength: 16, - keyLength: 32, + Memory: 64 * 1024, + Iterations: 3, + Parallelism: 2, + SaltLength: 16, + KeyLength: 32, } ) @@ -26,30 +26,30 @@ type OptFunc func(*Options) func SetMemory(memory uint32) OptFunc { return func(options *Options) { - options.memory = memory + options.Memory = memory } } func SetIterations(iterations uint32) OptFunc { return func(options *Options) { - options.iterations = iterations + options.Iterations = iterations } } func SetParallelism(parallelism uint8) OptFunc { return func(options *Options) { - options.parallelism = parallelism + options.Parallelism = parallelism } } func SetSaltLength(saltLength uint32) OptFunc { return func(options *Options) { - options.saltLength = saltLength + options.SaltLength = saltLength } } func SetKeyLength(keyLength uint32) OptFunc { return func(options *Options) { - options.keyLength = keyLength + options.KeyLength = keyLength } }