#
# PRE: if
#
string test_string
string test_hmac_key
string test_hmac_data
string dummy_string

octets result_octets

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

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

result_octets := %sha1("%{test_string}")
if (!(result_octets == 0xcc7edf1ccc4bdf1e0ec8f72b95388b65218ecf0c)) {
	test_fail
}

#
# SHA1 of empty string
#
result_octets := %sha1("%{dummy_string}")
if (!(result_octets == 0xda39a3ee5e6b4b0d3255bfef95601890afd80709)) {
	test_fail
}

#
#  SHA1 HMAC with attribute references
#
result_octets := %hmacsha1("%{test_hmac_key}", "%{test_hmac_data}")
if (!(result_octets == 0xeffcdf6ae5eb2fa2d27416d5f184df9c259a7c79)) {
	test_fail
}

#
#  SHA1 HMAC with empty key and data
#
dummy_string := ''
result_octets := %hmacsha1("%{dummy_string}", "%{dummy_string}")
if (!(result_octets == 0xfbdb1d1b18aa6c08324b7d64b71fb76370690e1d)) {
	test_fail
}

success
