Compare commits

...

3 Commits

Author SHA1 Message Date
a902c2d41f Merge pull request 'Set version and remove subpackages' (#3) from release/v1.1.0 into master
Reviewed-on: #3
2024-11-28 22:48:55 +01:00
c32e66bd1e
Set version and remove subpackages
All checks were successful
test argon2 package / check and test (pull_request) Successful in 19m15s
test argon2 package / check and test (push) Successful in 28m40s
2024-11-28 22:04:03 +01:00
Euphoria Laxis
829bc7340f Merge pull request 'staging/v0.1.2 new version 0.1.2' (#2) from staging/v0.1.2 into master
Reviewed-on: #2
2024-10-13 03:18:24 +02:00
7 changed files with 55 additions and 54 deletions

View File

@ -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

View File

@ -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 {

View File

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

View File

@ -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
View 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
View File

@ -1,4 +1,4 @@
module euphoria-laxis.fr/go-packages/argon2
module euphoria-laxis.fr/go-packages/argon2/v1.1.0
go 1.23

View File

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