Compare commits

..

No commits in common. "master" and "release/v0.1.2" have entirely different histories.

7 changed files with 57 additions and 54 deletions

View File

@ -1,9 +1,13 @@
name: test argon2 package
on:
push:
branches:
- staging/*
pull_request:
branches:
- master
- release/*
- staging/*
env:
GOPATH: /go_path

View File

@ -1,4 +1,4 @@
package argon2
package decoder
import (
"crypto/subtle"
@ -6,6 +6,7 @@ import (
"fmt"
"strings"
"euphoria-laxis.fr/go-packages/argon2/encoder"
"golang.org/x/crypto/argon2"
)
@ -15,10 +16,10 @@ func NewDecoder() *Decoder {
return new(Decoder)
}
func (decoder *Decoder) decodeHash(encodedHash string) (o *Options, salt, hash []byte, err error) {
func (decoder *Decoder) decodeHash(encodedHash string) (o *encoder.Options, salt, hash []byte, err error) {
values := strings.Split(encodedHash, "$")
if len(values) != 6 {
return nil, nil, nil, ErrInvalidHash
return nil, nil, nil, encoder.ErrInvalidHash
}
var version int
_, err = fmt.Sscanf(values[2], "v=%d", &version)
@ -26,9 +27,9 @@ func (decoder *Decoder) decodeHash(encodedHash string) (o *Options, salt, hash [
return nil, nil, nil, err
}
if version != argon2.Version {
return nil, nil, nil, ErrIncompatibleVersion
return nil, nil, nil, encoder.ErrIncompatibleVersion
}
o = new(Options)
o = new(encoder.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

View File

@ -1,30 +1,30 @@
package argon2_test
package decoder
import (
"testing"
"euphoria-laxis.fr/go-packages/argon2"
"euphoria-laxis.fr/go-packages/argon2/encoder"
)
func TestDecoder(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
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
}
e, _ := argon2.NewEncoder(opts...)
var err error
randomString, err = e.RandomString(32)
e, _ := encoder.NewEncoder(opts...)
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 := argon2.NewDecoder()
d := NewDecoder()
var match bool
match, err = d.CompareStringToHash(randomString, hashedString)
if err != nil {

View File

@ -1,4 +1,4 @@
package argon2
package encoder
import (
"crypto/rand"

33
encoder/encoder_test.go Normal file
View File

@ -0,0 +1,33 @@
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)
}
}

View File

@ -1,4 +1,4 @@
package argon2
package encoder
import "errors"

View File

@ -1,35 +0,0 @@
package argon2_test
import (
"testing"
"euphoria-laxis.fr/go-packages/argon2"
)
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)
}
}