Set version and remove subpackages
This commit is contained in:
parent
829bc7340f
commit
c32e66bd1e
|
@ -1,4 +1,4 @@
|
||||||
package decoder
|
package argon2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/subtle"
|
"crypto/subtle"
|
||||||
|
@ -6,7 +6,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"euphoria-laxis.fr/go-packages/argon2/encoder"
|
|
||||||
"golang.org/x/crypto/argon2"
|
"golang.org/x/crypto/argon2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -16,10 +15,10 @@ func NewDecoder() *Decoder {
|
||||||
return new(Decoder)
|
return new(Decoder)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (decoder *Decoder) decodeHash(encodedHash string) (o *encoder.Options, salt, hash []byte, err error) {
|
func (decoder *Decoder) decodeHash(encodedHash string) (o *Options, 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, encoder.ErrInvalidHash
|
return nil, nil, nil, ErrInvalidHash
|
||||||
}
|
}
|
||||||
var version int
|
var version int
|
||||||
_, err = fmt.Sscanf(values[2], "v=%d", &version)
|
_, err = fmt.Sscanf(values[2], "v=%d", &version)
|
||||||
|
@ -27,9 +26,9 @@ func (decoder *Decoder) decodeHash(encodedHash string) (o *encoder.Options, salt
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
if version != argon2.Version {
|
if version != argon2.Version {
|
||||||
return nil, nil, nil, encoder.ErrIncompatibleVersion
|
return nil, nil, nil, ErrIncompatibleVersion
|
||||||
}
|
}
|
||||||
o = new(encoder.Options)
|
o = new(Options)
|
||||||
_, err = fmt.Sscanf(values[3], "m=%d,t=%d,p=%d", &o.Memory, &o.Iterations, &o.Parallelism)
|
_, 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
|
|
@ -1,30 +1,30 @@
|
||||||
package decoder
|
package argon2_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"euphoria-laxis.fr/go-packages/argon2/encoder"
|
"euphoria-laxis.fr/go-packages/argon2/v1.1.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDecoder(t *testing.T) {
|
func TestDecoder(t *testing.T) {
|
||||||
opts := []encoder.OptFunc{
|
opts = []argon2.OptFunc{
|
||||||
encoder.SetMemory(32 * 1024), // 32 bits
|
argon2.SetMemory(32 * 1024), // 32 bits
|
||||||
encoder.SetParallelism(4), // 4 concurrent actions
|
argon2.SetParallelism(4), // 4 concurrent actions
|
||||||
encoder.SetKeyLength(32), // key length
|
argon2.SetKeyLength(32), // key length
|
||||||
encoder.SetSaltLength(32), // salt length
|
argon2.SetSaltLength(32), // salt length
|
||||||
encoder.SetIterations(4), // 4 iterations, should be fast since there's 4 concurrent actions
|
argon2.SetIterations(4), // 4 iterations, should be fast since there's 4 concurrent actions
|
||||||
}
|
}
|
||||||
e, _ := encoder.NewEncoder(opts...)
|
e, _ := argon2.NewEncoder(opts...)
|
||||||
randomString, err := e.RandomString(32)
|
var err error
|
||||||
|
randomString, err = e.RandomString(32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
var hashedString string
|
|
||||||
hashedString, err = e.HashString(randomString)
|
hashedString, err = e.HashString(randomString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
d := NewDecoder()
|
d := argon2.NewDecoder()
|
||||||
var match bool
|
var match bool
|
||||||
match, err = d.CompareStringToHash(randomString, hashedString)
|
match, err = d.CompareStringToHash(randomString, hashedString)
|
||||||
if err != nil {
|
if err != nil {
|
|
@ -1,4 +1,4 @@
|
||||||
package encoder
|
package argon2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
|
@ -1,33 +0,0 @@
|
||||||
package encoder
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
randomString, hashedString string
|
|
||||||
opts []OptFunc
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestOptions(t *testing.T) {
|
|
||||||
opts = []OptFunc{
|
|
||||||
SetMemory(32 * 1024), // 32 bits
|
|
||||||
SetParallelism(4), // 4 concurrent actions
|
|
||||||
SetKeyLength(32), // key length
|
|
||||||
SetSaltLength(32), // salt length
|
|
||||||
SetIterations(4), // 4 iterations, should be fast since there's 4 concurrent actions
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEncoder(t *testing.T) {
|
|
||||||
var err error
|
|
||||||
e, _ := NewEncoder(opts...)
|
|
||||||
randomString, err = e.RandomString(32)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
hashedString, err = e.HashString(randomString)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
35
encoder_test.go
Normal file
35
encoder_test.go
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
package argon2_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"euphoria-laxis.fr/go-packages/argon2/v1.1.0"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
randomString, hashedString string
|
||||||
|
opts []argon2.OptFunc
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestOptions(t *testing.T) {
|
||||||
|
opts = []argon2.OptFunc{
|
||||||
|
argon2.SetMemory(32 * 1024), // 32 bits
|
||||||
|
argon2.SetParallelism(4), // 4 concurrent actions
|
||||||
|
argon2.SetKeyLength(32), // key length
|
||||||
|
argon2.SetSaltLength(32), // salt length
|
||||||
|
argon2.SetIterations(4), // 4 iterations, should be fast since there's 4 concurrent actions
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEncoder(t *testing.T) {
|
||||||
|
var err error
|
||||||
|
e, _ := argon2.NewEncoder(opts...)
|
||||||
|
randomString, err = e.RandomString(32)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
hashedString, err = e.HashString(randomString)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
2
go.mod
2
go.mod
|
@ -1,4 +1,4 @@
|
||||||
module euphoria-laxis.fr/go-packages/argon2
|
module euphoria-laxis.fr/go-packages/argon2/v1.1.0
|
||||||
|
|
||||||
go 1.23
|
go 1.23
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package encoder
|
package argon2
|
||||||
|
|
||||||
import "errors"
|
import "errors"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user