argon2/decoder_test.go

52 lines
1.1 KiB
Go
Raw Normal View History

2024-11-28 22:01:52 +01:00
package argon2_test
2024-07-24 19:42:25 +02:00
import (
"testing"
2024-11-28 22:01:52 +01:00
"euphoria-laxis.fr/go-packages/argon2/v1.1.0"
2024-07-24 19:42:25 +02:00
)
func TestDecoder(t *testing.T) {
2024-11-28 22:01:52 +01:00
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, _ := argon2.NewEncoder(opts...)
var err error
randomString, err = e.RandomString(32)
2024-07-24 19:42:25 +02:00
if err != nil {
t.Fatal(err)
}
hashedString, err = e.HashString(randomString)
if err != nil {
t.Fatal(err)
}
2024-11-28 22:01:52 +01:00
d := argon2.NewDecoder()
2024-07-24 19:42:25 +02:00
var match bool
match, err = d.CompareStringToHash(randomString, hashedString)
if err != nil {
t.Fatal(err)
}
if !match {
t.Log("passwords comparison failed")
t.Log("passwords should match")
t.Fail()
}
randomString, err = e.RandomString(32)
if err != nil {
t.Fatal(err)
}
match, err = d.CompareStringToHash(randomString, hashedString)
if err != nil {
t.Fatal(err)
}
if match {
t.Log("passwords comparison failed")
t.Log("passwords shouldn't match")
t.Fail()
}
}