summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-09-30 21:06:44 -0300
committerEuAndreh <eu@euandre.org>2024-09-30 21:06:44 -0300
commit2e414ddc0a76340353791a9a7c4e6d0b7dc6f4cf (patch)
treecb45cafae1c930c0346779556c110b166e35bac8
parentAdd noop mkdeps.sh and empty deps.mk file (diff)
downloadscrypt-2e414ddc0a76340353791a9a7c4e6d0b7dc6f4cf.tar.gz
scrypt-2e414ddc0a76340353791a9a7c4e6d0b7dc6f4cf.tar.xz
tests/scrypt.go: Depend on gobang
-rw-r--r--tests/scrypt.go142
1 files changed, 45 insertions, 97 deletions
diff --git a/tests/scrypt.go b/tests/scrypt.go
index 58e4341..16ea570 100644
--- a/tests/scrypt.go
+++ b/tests/scrypt.go
@@ -5,51 +5,11 @@ import (
"crypto/sha256"
"encoding/base64"
"encoding/hex"
- "fmt"
"hash"
- "os"
- "reflect"
-)
-
-
-
-func showColour() bool {
- return os.Getenv("NO_COLOUR") == ""
-}
-func testStart(name string) {
- fmt.Fprintf(os.Stderr, "%s:\n", name)
-}
-
-func testing(message string, body func()) {
- if showColour() {
- fmt.Fprintf(
- os.Stderr,
- "\033[0;33mtesting\033[0m: %s... ",
- message,
- )
- body()
- fmt.Fprintf(os.Stderr, "\033[0;32mOK\033[0m.\n")
- } else {
- fmt.Fprintf(os.Stderr, "testing: %s... ", message)
- body()
- fmt.Fprintf(os.Stderr, "OK.\n")
- }
-}
+ g "gobang"
+)
-func assertEq(given any, expected any) {
- if !reflect.DeepEqual(given, expected) {
- if showColour() {
- fmt.Fprintf(os.Stderr, "\033[0;31mERR\033[0m.\n")
- } else {
- fmt.Fprintf(os.Stderr, "ERR.\n")
- }
- fmt.Fprintf(os.Stderr, "given != expected\n")
- fmt.Fprintf(os.Stderr, "given: %#v\n", given)
- fmt.Fprintf(os.Stderr, "expected: %#v\n", expected)
- os.Exit(1)
- }
-}
type pbkdfTestVector struct {
@@ -188,18 +148,18 @@ func testHash(h func() hash.Hash, hashName string, vectors []pbkdfTestVector) {
len(v.output),
h,
)
- assertEq(out, v.output)
+ g.TAssertEqual(out, v.output)
}
}
func test__PBKDF() {
- testStart("_PBKDF()")
+ g.TestStart("_PBKDF()")
- testing("HMAC with SHA1", func() {
+ g.Testing("HMAC with SHA1", func() {
testHash(sha1.New, "SHA1", sha1TestVectors)
})
- testing("HMAC with SHA256", func() {
+ g.Testing("HMAC with SHA256", func() {
testHash(sha256.New, "SHA256", sha256TestVectors)
})
}
@@ -338,30 +298,10 @@ var bad = []scryptTestVector {
{"p", "s", 16, halfMax, halfMax, nil, ErrParamsTooLarge}, // p * r too large
}
-func test_validParams() {
- testStart("validParams()")
-
- return // FIXME
- testing("bad hashes", func() {
- for _, v := range bad {
- _, err := scrypt(
- []byte(v.password),
- []byte(v.salt),
- v.N,
- v.r,
- v.p,
- 32,
- )
- // fmt.Println("N: %#v\n", v.N)
- assertEq(err, v.err)
- }
- })
-}
-
func test_scrypt() {
- testStart("scrypt()")
+ g.TestStart("scrypt()")
- testing("good hashes", func() {
+ g.Testing("good hashes", func() {
for _, v := range good {
k, err := scrypt(
[]byte(v.password),
@@ -371,12 +311,12 @@ func test_scrypt() {
v.p,
len(v.output),
)
- assertEq(err, nil)
- assertEq(k, v.output)
+ g.TAssertEqual(err, nil)
+ g.TAssertEqual(k, v.output)
}
})
- testing("bad hashes", func() {
+ g.Testing("bad hashes", func() {
for _, v := range bad {
_, err := scrypt(
[]byte(v.password),
@@ -386,12 +326,11 @@ func test_scrypt() {
v.p,
32,
)
- // fmt.Println("N: %#v\n", v.N)
- assertEq(err, v.err)
+ g.TAssertEqual(err, v.err)
}
})
- testing("example value", func() {
+ g.Testing("example value", func() {
const expected = "lGnMz8io0AUkfzn6Pls1qX20Vs7PGN6sbYQ2TQgY12M="
// DO NOT use this salt value; generate your own random salt.
// 8 bytes is a good length.
@@ -405,58 +344,67 @@ func test_scrypt() {
1,
32,
)
- assertEq(err, nil)
+ g.TAssertEqual(err, nil)
given := base64.StdEncoding.EncodeToString(dk)
- assertEq(given, expected)
+ g.TAssertEqual(given, expected)
})
}
-func test_Random() {
- testStart("Random()")
+func test_SaltFrom() {
+ g.TestStart("SaltFrom()")
+ // FIXME
+}
-/*
-FIXME
- testing("we get the desired output size", func() {
- for i := 0; i < 100; i++ {
- buffer := Random(i)
- assertEq(len(buffer), i)
- }
- })
- */
+func test_HashFrom() {
+ g.TestStart("HashFrom()")
+ // FIXME
+}
+
+func test_CheckFrom() {
+ g.TestStart("CheckFrom()")
+ // FIXME
}
func test_Salt() {
- testStart("Salt()")
+ g.TestStart("Salt()")
- testing("we generate a random salt of a fixed size", func() {
+ g.Testing("we generate a random salt of a fixed size", func() {
salt := Salt()
- assertEq(len(salt), saltMinLength)
+ g.TAssertEqual(len(salt), saltMinLength)
var buffer [saltMinLength * 2]byte
hex.Encode(buffer[:], salt)
- fmt.Fprintf(os.Stderr, "%s ", string(buffer[:]))
+ // FIXME
})
}
func test_Hash() {
- testStart("Hash()")
+ g.TestStart("Hash()")
- testing("same input, same output", func() {
+ g.Testing("same input, same output", func() {
password := Salt()
salt := Salt()
hash1 := Hash(password, salt)
hash2 := Hash(password, salt)
- assertEq(hash1, hash2)
+ g.TAssertEqual(hash1, hash2)
})
}
+func test_Check() {
+ g.TestStart("Check()")
+ // FIXME
+}
+
+
func MainTest() {
test__PBKDF()
- test_validParams()
test_scrypt()
- test_Hash()
- test_Random()
+ test_SaltFrom()
+ test_HashFrom()
+ test_CheckFrom()
test_Salt()
+ test_Hash()
+ test_Check()
}