Created
March 19, 2018 21:00
-
-
Save lansana/d910d16bea03b0ee81945ce6f7ccf46b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hmac | |
import ( | |
"crypto/sha256" | |
"crypto/sha512" | |
"testing" | |
) | |
func TestValidateCustomHashSuccess(t *testing.T) { | |
key := []byte("123456") | |
message := []byte("Hello") | |
hmac := New(sha512.New, key, message) | |
if !Validate(sha512.New, key, message, hmac) { | |
t.Errorf("Expected to get %#v, got %#v", true, false) | |
} | |
} | |
func TestValidateMismatchedHash(t *testing.T) { | |
key := []byte("123456") | |
message := []byte("Hello") | |
hmac := New(sha512.New, key, message) | |
if Validate(sha256.New, key, message, hmac) { | |
t.Errorf("Expected to get %#v, got %#v", false, true) | |
} | |
} | |
func TestValidateHexCustomHashSuccess(t *testing.T) { | |
key := []byte("123456") | |
message := []byte("Hello") | |
hmac := []byte(HexDigest(sha512.New, key, message)) | |
if !ValidateHex(sha512.New, key, message, hmac) { | |
t.Errorf("Expected to get %#v, got %#v", true, false) | |
} | |
} | |
func TestValidateHexMismatchedHash(t *testing.T) { | |
key := []byte("123456") | |
message := []byte("Hello") | |
hmac := []byte(HexDigest(sha512.New, key, message)) | |
if ValidateHex(sha256.New, key, message, hmac) { | |
t.Errorf("Expected to get %#v, got %#v", false, true) | |
} | |
} | |
func TestValidateBase64CustomHashSuccess(t *testing.T) { | |
key := []byte("123456") | |
message := []byte("Hello") | |
hmac := []byte(Base64Digest(sha512.New, key, message)) | |
if !ValidateBase64(sha512.New, key, message, hmac) { | |
t.Errorf("Expected to get %#v, got %#v", true, false) | |
} | |
} | |
func TestValidateBase64MismatchedHash(t *testing.T) { | |
key := []byte("123456") | |
message := []byte("Hello") | |
hmac := []byte(Base64Digest(sha512.New, key, message)) | |
if ValidateBase64(sha256.New, key, message, hmac) { | |
t.Errorf("Expected to get %#v, got %#v", false, true) | |
} | |
} | |
func TestValidateHexSha512(t *testing.T) { | |
key := []byte("123456") | |
message := []byte("Hello") | |
hmac := []byte(HexSha512(key, message)) | |
if !ValidateHexSha512(key, message, hmac) { | |
t.Errorf("Expected to get %#v, got %#v", true, false) | |
} | |
} | |
func TestValidateHexSha256(t *testing.T) { | |
key := []byte("123456") | |
message := []byte("Hello") | |
hmac := []byte(HexSha256(key, message)) | |
if !ValidateHexSha256(key, message, hmac) { | |
t.Errorf("Expected to get %#v, got %#v", true, false) | |
} | |
} | |
func TestValidateBase64Sha512(t *testing.T) { | |
key := []byte("123456") | |
message := []byte("Hello") | |
hmac := []byte(Base64Sha512(key, message)) | |
if !ValidateBase64Sha512(key, message, hmac) { | |
t.Errorf("Expected to get %#v, got %#v", true, false) | |
} | |
} | |
func TestValidateBase64Sha256(t *testing.T) { | |
key := []byte("123456") | |
message := []byte("Hello") | |
hmac := []byte(Base64Sha256(key, message)) | |
if !ValidateBase64Sha256(key, message, hmac) { | |
t.Errorf("Expected to get %#v, got %#v", true, false) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment