From b93851702aebb65a100cb09635e24d1b5788ef6f Mon Sep 17 00:00:00 2001 From: Oleg Kovalov Date: Wed, 14 Apr 2021 09:57:49 +0200 Subject: [PATCH] rename key vars in tests (#108) --- algo_eddsa_test.go | 10 +++++----- algo_es_test.go | 22 +++++++++++----------- algo_hs_test.go | 34 ++++++++++++++++++++++------------ algo_ps_test.go | 12 ++++++------ algo_rs_test.go | 22 +++++++++++----------- algo_test.go | 14 ++++++-------- 6 files changed, 61 insertions(+), 53 deletions(-) diff --git a/algo_eddsa_test.go b/algo_eddsa_test.go index ffeba32..65a3b4a 100644 --- a/algo_eddsa_test.go +++ b/algo_eddsa_test.go @@ -11,8 +11,8 @@ var ( ed25519PrivateKey ed25519.PrivateKey ed25519PublicKey ed25519.PublicKey - ed25519OtherPrivateKey ed25519.PrivateKey - ed25519OtherPublicKey ed25519.PublicKey + ed25519PrivateKeyAnother ed25519.PrivateKey + ed25519PublicKeyAnother ed25519.PublicKey ) func init() { @@ -25,7 +25,7 @@ func init() { } ed25519PrivateKey, ed25519PublicKey = f() - ed25519OtherPrivateKey, ed25519OtherPublicKey = f() + ed25519PrivateKeyAnother, ed25519PublicKeyAnother = f() } func TestEdDSA(t *testing.T) { @@ -46,8 +46,8 @@ func TestEdDSA(t *testing.T) { } f(ed25519PrivateKey, ed25519PublicKey, true) - f(ed25519PrivateKey, ed25519OtherPublicKey, false) - f(ed25519OtherPrivateKey, ed25519PublicKey, false) + f(ed25519PrivateKey, ed25519PublicKeyAnother, false) + f(ed25519PrivateKeyAnother, ed25519PublicKey, false) } func TestEdDSA_BadKeys(t *testing.T) { diff --git a/algo_es_test.go b/algo_es_test.go index 2e4324f..959d710 100644 --- a/algo_es_test.go +++ b/algo_es_test.go @@ -12,8 +12,8 @@ var ( ecdsaPublicKey256, ecdsaPublicKey384, ecdsaPublicKey521 *ecdsa.PublicKey ecdsaPrivateKey256, ecdsaPrivateKey384, ecdsaPrivateKey521 *ecdsa.PrivateKey - ecdsaOtherPublicKey256, ecdsaOtherPublicKey384, ecdsaOtherPublicKey521 *ecdsa.PublicKey - ecdsaOtherPrivateKey256, ecdsaOtherPrivateKey384, ecdsaOtherPrivateKey521 *ecdsa.PrivateKey + ecdsaPublicKey256Another, ecdsaPublicKey384Another, ecdsaPublicKey521Another *ecdsa.PublicKey + ecdsaPrivateKey256Another, ecdsaPrivateKey384Another, ecdsaPrivateKey521Another *ecdsa.PrivateKey ) func init() { @@ -29,9 +29,9 @@ func init() { ecdsaPrivateKey384, ecdsaPublicKey384 = f(elliptic.P384) ecdsaPrivateKey521, ecdsaPublicKey521 = f(elliptic.P521) - ecdsaOtherPrivateKey256, ecdsaOtherPublicKey256 = f(elliptic.P256) - ecdsaOtherPrivateKey384, ecdsaOtherPublicKey384 = f(elliptic.P384) - ecdsaOtherPrivateKey521, ecdsaOtherPublicKey521 = f(elliptic.P521) + ecdsaPrivateKey256Another, ecdsaPublicKey256Another = f(elliptic.P256) + ecdsaPrivateKey384Another, ecdsaPublicKey384Another = f(elliptic.P384) + ecdsaPrivateKey521Another, ecdsaPublicKey521Another = f(elliptic.P521) } func TestES(t *testing.T) { @@ -55,13 +55,13 @@ func TestES(t *testing.T) { f(ES384, ecdsaPrivateKey384, ecdsaPublicKey384, true) f(ES512, ecdsaPrivateKey521, ecdsaPublicKey521, true) - f(ES256, ecdsaPrivateKey256, ecdsaOtherPublicKey256, false) - f(ES384, ecdsaPrivateKey384, ecdsaOtherPublicKey384, false) - f(ES512, ecdsaPrivateKey521, ecdsaOtherPublicKey521, false) + f(ES256, ecdsaPrivateKey256, ecdsaPublicKey256Another, false) + f(ES384, ecdsaPrivateKey384, ecdsaPublicKey384Another, false) + f(ES512, ecdsaPrivateKey521, ecdsaPublicKey521Another, false) - f(ES256, ecdsaOtherPrivateKey256, ecdsaPublicKey256, false) - f(ES384, ecdsaOtherPrivateKey384, ecdsaPublicKey384, false) - f(ES512, ecdsaOtherPrivateKey521, ecdsaPublicKey521, false) + f(ES256, ecdsaPrivateKey256Another, ecdsaPublicKey256, false) + f(ES384, ecdsaPrivateKey384Another, ecdsaPublicKey384, false) + f(ES512, ecdsaPrivateKey521Another, ecdsaPublicKey521, false) } func TestES_BadKeys(t *testing.T) { diff --git a/algo_hs_test.go b/algo_hs_test.go index b49161c..f101d62 100644 --- a/algo_hs_test.go +++ b/algo_hs_test.go @@ -4,8 +4,18 @@ import ( "testing" ) +var ( + hsKey256 = []byte("hmac-secret-key-256") + hsKey384 = []byte("hmac-secret-key-384") + hsKey512 = []byte("hmac-secret-key-512") + + hsKeyAnother256 = []byte("hmac-secret-key-256-another") + hsKeyAnother384 = []byte("hmac-secret-key-384-another") + hsKeyAnother512 = []byte("hmac-secret-key-512-another") +) + func TestHS(t *testing.T) { - f := func(alg Algorithm, signKey, verifyKey string, isCorrectSign bool) { + f := func(alg Algorithm, signKey, verifyKey []byte, isCorrectSign bool) { t.Helper() const payload = `simple-string-payload` @@ -21,21 +31,21 @@ func TestHS(t *testing.T) { } } - f(HS256, `hmac-secret-key`, `hmac-secret-key`, true) - f(HS384, `hmac-secret-key`, `hmac-secret-key`, true) - f(HS512, `hmac-secret-key`, `hmac-secret-key`, true) + f(HS256, hsKey256, hsKey256, true) + f(HS384, hsKey384, hsKey384, true) + f(HS512, hsKey512, hsKey512, true) - f(HS256, `key_1`, `1_key`, false) - f(HS384, `key_1`, `1_key`, false) - f(HS512, `key_1`, `1_key`, false) + f(HS256, hsKey256, hsKeyAnother256, false) + f(HS384, hsKey384, hsKeyAnother384, false) + f(HS512, hsKey512, hsKeyAnother512, false) - f(HS256, `hmac-secret-key`, `key_1`, false) + f(HS256, hsKey256, hsKeyAnother256, false) } -func hsSign(t *testing.T, alg Algorithm, key, payload string) []byte { +func hsSign(t *testing.T, alg Algorithm, key []byte, payload string) []byte { t.Helper() - signer, errSigner := NewSignerHS(alg, []byte(key)) + signer, errSigner := NewSignerHS(alg, key) if errSigner != nil { t.Fatalf("NewSignerHS %v", errSigner) } @@ -47,10 +57,10 @@ func hsSign(t *testing.T, alg Algorithm, key, payload string) []byte { return sign } -func hsVerify(t *testing.T, alg Algorithm, key, payload string, sign []byte) error { +func hsVerify(t *testing.T, alg Algorithm, key []byte, payload string, sign []byte) error { t.Helper() - verifier, errVerifier := NewVerifierHS(alg, []byte(key)) + verifier, errVerifier := NewVerifierHS(alg, key) if errVerifier != nil { t.Fatalf("NewVerifierHS %v", errVerifier) } diff --git a/algo_ps_test.go b/algo_ps_test.go index 43decc6..3e6ab4f 100644 --- a/algo_ps_test.go +++ b/algo_ps_test.go @@ -27,13 +27,13 @@ func TestPS(t *testing.T) { f(PS384, rsaPrivateKey384, rsaPublicKey384, true) f(PS512, rsaPrivateKey512, rsaPublicKey512, true) - f(PS256, rsaPrivateKey256, rsaOtherPublicKey256, false) - f(PS384, rsaPrivateKey384, rsaOtherPublicKey384, false) - f(PS512, rsaPrivateKey512, rsaOtherPublicKey512, false) + f(PS256, rsaPrivateKey256, rsaPublicKey256Another, false) + f(PS384, rsaPrivateKey384, rsaPublicKey384Another, false) + f(PS512, rsaPrivateKey512, rsaPublicKey512Another, false) - f(PS256, rsaOtherPrivateKey256, rsaPublicKey256, false) - f(PS384, rsaOtherPrivateKey384, rsaPublicKey384, false) - f(PS512, rsaOtherPrivateKey512, rsaPublicKey512, false) + f(PS256, rsaPrivateKey256Another, rsaPublicKey256, false) + f(PS384, rsaPrivateKey384Another, rsaPublicKey384, false) + f(PS512, rsaPrivateKey512Another, rsaPublicKey512, false) } func TestPS_BadKeys(t *testing.T) { diff --git a/algo_rs_test.go b/algo_rs_test.go index 672f8f9..a0ffa2d 100644 --- a/algo_rs_test.go +++ b/algo_rs_test.go @@ -11,8 +11,8 @@ var ( rsaPublicKey256, rsaPublicKey384, rsaPublicKey512 *rsa.PublicKey rsaPrivateKey256, rsaPrivateKey384, rsaPrivateKey512 *rsa.PrivateKey - rsaOtherPublicKey256, rsaOtherPublicKey384, rsaOtherPublicKey512 *rsa.PublicKey - rsaOtherPrivateKey256, rsaOtherPrivateKey384, rsaOtherPrivateKey512 *rsa.PrivateKey + rsaPublicKey256Another, rsaPublicKey384Another, rsaPublicKey512Another *rsa.PublicKey + rsaPrivateKey256Another, rsaPrivateKey384Another, rsaPrivateKey512Another *rsa.PrivateKey ) func init() { @@ -28,9 +28,9 @@ func init() { rsaPrivateKey384, rsaPublicKey384 = f(384 * 8) rsaPrivateKey512, rsaPublicKey512 = f(512 * 8) - rsaOtherPrivateKey256, rsaOtherPublicKey256 = f(256 * 8) - rsaOtherPrivateKey384, rsaOtherPublicKey384 = f(384 * 8) - rsaOtherPrivateKey512, rsaOtherPublicKey512 = f(512 * 8) + rsaPrivateKey256Another, rsaPublicKey256Another = f(256 * 8) + rsaPrivateKey384Another, rsaPublicKey384Another = f(384 * 8) + rsaPrivateKey512Another, rsaPublicKey512Another = f(512 * 8) } func TestRS(t *testing.T) { @@ -54,13 +54,13 @@ func TestRS(t *testing.T) { f(RS384, rsaPrivateKey384, rsaPublicKey384, true) f(RS512, rsaPrivateKey512, rsaPublicKey512, true) - f(RS256, rsaPrivateKey256, rsaOtherPublicKey256, false) - f(RS384, rsaPrivateKey384, rsaOtherPublicKey384, false) - f(RS512, rsaPrivateKey512, rsaOtherPublicKey512, false) + f(RS256, rsaPrivateKey256, rsaPublicKey256Another, false) + f(RS384, rsaPrivateKey384, rsaPublicKey384Another, false) + f(RS512, rsaPrivateKey512, rsaPublicKey512Another, false) - f(RS256, rsaOtherPrivateKey256, rsaPublicKey256, false) - f(RS384, rsaOtherPrivateKey384, rsaPublicKey384, false) - f(RS512, rsaOtherPrivateKey512, rsaPublicKey512, false) + f(RS256, rsaPrivateKey256Another, rsaPublicKey256, false) + f(RS384, rsaPrivateKey384Another, rsaPublicKey384, false) + f(RS512, rsaPrivateKey512Another, rsaPublicKey512, false) } func TestRS_BadKeys(t *testing.T) { diff --git a/algo_test.go b/algo_test.go index d54c429..db12f4c 100644 --- a/algo_test.go +++ b/algo_test.go @@ -12,10 +12,9 @@ func TestSignerAlg(t *testing.T) { } } - hmacKey := []byte("key") - f(mustSigner(NewSignerHS(HS256, hmacKey)), HS256) - f(mustSigner(NewSignerHS(HS384, hmacKey)), HS384) - f(mustSigner(NewSignerHS(HS512, hmacKey)), HS512) + f(mustSigner(NewSignerHS(HS256, hsKey256)), HS256) + f(mustSigner(NewSignerHS(HS384, hsKey384)), HS384) + f(mustSigner(NewSignerHS(HS512, hsKey512)), HS512) f(mustSigner(NewSignerRS(RS256, rsaPrivateKey256)), RS256) f(mustSigner(NewSignerRS(RS384, rsaPrivateKey384)), RS384) @@ -38,10 +37,9 @@ func TestVerifierAlg(t *testing.T) { } } - hmacKey := []byte("key") - f(mustVerifier(NewVerifierHS(HS256, hmacKey)), HS256) - f(mustVerifier(NewVerifierHS(HS384, hmacKey)), HS384) - f(mustVerifier(NewVerifierHS(HS512, hmacKey)), HS512) + f(mustVerifier(NewVerifierHS(HS256, hsKey256)), HS256) + f(mustVerifier(NewVerifierHS(HS384, hsKey384)), HS384) + f(mustVerifier(NewVerifierHS(HS512, hsKey512)), HS512) f(mustVerifier(NewVerifierRS(RS256, rsaPublicKey256)), RS256) f(mustVerifier(NewVerifierRS(RS384, rsaPublicKey384)), RS384)