Compare commits
3 Commits
staging/v0
...
master
Author | SHA1 | Date | |
---|---|---|---|
a902c2d41f | |||
c32e66bd1e | |||
|
829bc7340f |
|
@ -1,4 +1,4 @@
|
|||
package decoder
|
||||
package argon2
|
||||
|
||||
import (
|
||||
"crypto/subtle"
|
||||
|
@ -6,7 +6,6 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"euphoria-laxis.fr/go-packages/argon2/encoder"
|
||||
"golang.org/x/crypto/argon2"
|
||||
)
|
||||
|
||||
|
@ -16,10 +15,10 @@ func NewDecoder() *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, "$")
|
||||
if len(values) != 6 {
|
||||
return nil, nil, nil, encoder.ErrInvalidHash
|
||||
return nil, nil, nil, ErrInvalidHash
|
||||
}
|
||||
var version int
|
||||
_, 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
|
||||
}
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
|
@ -1,30 +1,30 @@
|
|||
package decoder
|
||||
package argon2_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"euphoria-laxis.fr/go-packages/argon2/encoder"
|
||||
"euphoria-laxis.fr/go-packages/argon2/v1.1.0"
|
||||
)
|
||||
|
||||
func TestDecoder(t *testing.T) {
|
||||
opts := []encoder.OptFunc{
|
||||
encoder.SetMemory(32 * 1024), // 32 bits
|
||||
encoder.SetParallelism(4), // 4 concurrent actions
|
||||
encoder.SetKeyLength(32), // key length
|
||||
encoder.SetSaltLength(32), // salt length
|
||||
encoder.SetIterations(4), // 4 iterations, should be fast since there's 4 concurrent actions
|
||||
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
|
||||
}
|
||||
e, _ := encoder.NewEncoder(opts...)
|
||||
randomString, err := e.RandomString(32)
|
||||
e, _ := argon2.NewEncoder(opts...)
|
||||
var err error
|
||||
randomString, err = e.RandomString(32)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var hashedString string
|
||||
hashedString, err = e.HashString(randomString)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
d := NewDecoder()
|
||||
d := argon2.NewDecoder()
|
||||
var match bool
|
||||
match, err = d.CompareStringToHash(randomString, hashedString)
|
||||
if err != nil {
|
|
@ -1,4 +1,4 @@
|
|||
package encoder
|
||||
package argon2
|
||||
|
||||
import (
|
||||
"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
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package encoder
|
||||
package argon2
|
||||
|
||||
import "errors"
|
||||
|
Loading…
Reference in New Issue
Block a user