#
# PRE: if
#
string test_string
string dummy_string
string test_hmac_key
string test_hmac_data
octets test_octets
octets result_octets

test_string := "This is a string\n"
test_octets := 0x000504030201
test_hmac_key := "what do ya want for nothing?"
test_hmac_data := "Jefe"

#
#  Put "This is a string" into a file and call "md5sum" on it.
#  You should get this string.
#
result_octets := %md5("This is a string\n")
if (!(result_octets == 0x9ac4dbbc3c0ad2429e61d0df5dc28add)) {
	test_fail
}

result_octets := %md5("%{test_string}")
if (!(result_octets == 0x9ac4dbbc3c0ad2429e61d0df5dc28add)) {
	test_fail
}

#
#  MD5 should also be able to cope with references to octet attributes
#
result_octets := %md5("%{test_octets}")
if (!(result_octets == 0xc1e7fa505b2fc1fd0da6cac3db6f6f44)) {
	test_fail
}

#
#  MD5 of null string is d41d8cd98f00b204e9800998ecf8427e
#
result_octets := %md5("%{dummy_string}")
if (!(result_octets == 0xd41d8cd98f00b204e9800998ecf8427e)) {
	test_fail
}

#
#  MD5 HMAC with attribute references
#
result_octets := %hmacmd5("%{test_hmac_key}", "%{test_hmac_data}")
if (!(result_octets == 0x750c783e6ab0b503eaa86e310a5db738)) {
	test_fail
}

#
#  MD5 HMAC with empty key and data
#
dummy_string := ''
result_octets := %hmacmd5("%{dummy_string}", "%{dummy_string}")
if (!(result_octets == 0x74e6f7298a9c2d168935f58c001bad88)) {
	test_fail
}

success
