Created
March 17, 2018 09:07
-
-
Save silbinarywolf/27ddca16343e274bb259096881dea67d to your computer and use it in GitHub Desktop.
hmac_md5_test
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
/// @function hmac_md5_test | |
/// @description Runs tests to ensure the correctness of hmac_md5 | |
var reportString = "hmac_md5_test() Test Report:\n\n" | |
var testCount = 0 | |
var passCount = 0 | |
var failCount = 0 | |
#region Test "A" string with "secret_key" as key | |
var test_name = "\"A\" string with \"secret_key\" as key" | |
var str = "A" | |
var secret_key = "secret_key" | |
var hmac_result = "" | |
var expected_value = "ee133c384b21ea75f917d6840834b819" | |
#region internal function | |
var buffer = buffer_create(string_length(str), buffer_fixed, 1) | |
buffer_write(buffer, buffer_text, str) | |
var hmac_result = hmac_md5(buffer, 0, buffer_get_size(buffer), secret_key) | |
buffer_delete(buffer) | |
if hmac_result == expected_value { | |
passCount++ | |
} else { | |
reportString += "- Expected test ("+test_name+") to be:\n"+expected_value+"\ninstead got:\n"+hmac_result+"\n\n"; | |
failCount++ | |
} | |
testCount++ | |
#endregion | |
#endregion | |
#region Test "A" string with zero-byte terminator with "secret_key" as key | |
var test_name = "\"A\" string with zero byte terminator with \"secret_key\" as key" | |
var str = "A" | |
var secret_key = "secret_key" | |
var hmac_result = "" | |
var expected_value = "099bf9b598496a45c2dd81fa8fa5942d" | |
#region internal function | |
var buffer = buffer_create(string_length(str)+1, buffer_fixed, 1) | |
buffer_write(buffer, buffer_string, str) | |
var hmac_result = hmac_md5(buffer, 0, buffer_get_size(buffer), secret_key) | |
buffer_delete(buffer) | |
if hmac_result == expected_value { | |
passCount++ | |
} else { | |
reportString += "- Expected test ("+test_name+") to be:\n"+expected_value+"\ninstead got:\n"+hmac_result+"\n\n"; | |
failCount++ | |
} | |
testCount++ | |
#endregion | |
#endregion | |
#region Test "A" string with "ff772e31410ae7f31b93c2109f496006ff772e31410ae7f31b93c2109f496006" as key | |
var test_name = "\"A\" string with \"ff772e31410ae7f31b93c2109f496006ff772e31410ae7f31b93c2109f496006\" as key" | |
var str = "A" | |
var secret_key = "ff772e31410ae7f31b93c2109f496006ff772e31410ae7f31b93c2109f496006" | |
var hmac_result = "" | |
var expected_value = "2efd7338eeb40b0ef11d89baa7a41d7a" | |
#region internal function | |
var buffer = buffer_create(string_length(str), buffer_fixed, 1) | |
buffer_write(buffer, buffer_text, str) | |
var hmac_result = hmac_md5(buffer, 0, buffer_get_size(buffer), secret_key) | |
buffer_delete(buffer) | |
if hmac_result == expected_value { | |
passCount++ | |
} else { | |
reportString += "- Expected test ("+test_name+") to be:\n"+expected_value+"\ninstead got:\n"+hmac_result+"\n\n"; | |
failCount++ | |
} | |
testCount++ | |
#endregion | |
#endregion | |
#region Test "A" string with "ff772e31410ae7f31b93c2109f496006ff772e31410ae7f31b93c2109f496006" as key | |
var test_name = "\"A\" string with zero byte terminator with \"ff772e31410ae7f31b93c2109f496006ff772e31410ae7f31b93c2109f496006\" as key" | |
var str = "A" | |
var secret_key = "ff772e31410ae7f31b93c2109f496006ff772e31410ae7f31b93c2109f496006" | |
var hmac_result = "" | |
var expected_value = "25285069c4041dea67bfc513ee244b14" | |
#region internal function | |
var buffer = buffer_create(string_length(str)+1, buffer_fixed, 1) | |
buffer_write(buffer, buffer_string, str) | |
var hmac_result = hmac_md5(buffer, 0, buffer_get_size(buffer), secret_key) | |
buffer_delete(buffer) | |
if hmac_result == expected_value { | |
passCount++ | |
} else { | |
reportString += "- Expected test ("+test_name+") to be:\n"+expected_value+"\ninstead got:\n"+hmac_result+"\n\n"; | |
failCount++ | |
} | |
testCount++ | |
#endregion | |
#endregion | |
// End process. | |
// Tests should be executed to test behaviour and not used in actual game code. | |
reportString += string(testCount)+" tests, "+string(passCount)+" passed and "+string(failCount)+" failed.\n"; | |
show_debug_message(reportString) | |
show_message(reportString) | |
game_end() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment