HMAC issue

Hi,

trying to use the HMAC support from the library and running into an error I can’t figure out. Any help would be great. My function:


Function HMAC(msg As String) As String
	hmac = CreateObject("roHMAC") 
	privateKey = CreateObject("roByteArray") 
	privateKey.fromBase64String("k3U6GLkZOoNIoSgjDshPErvqMIFdE0xMTx8kgsrhnC0=")
	result = hmac.setup("sha1", privateKey)
	print "result";result
	if result = 0
		message = CreateObject("roByteArray") 
		message.fromAsciiString(msg) 
		result = hmac.process(message) 
		return result.toBase64String()
	end if
End Function

and the resultant error:


Current Function:
274: Function HMAC(msg As String) As String
275: 	hmac = CreateObject("roHMAC") 
276: 	privateKey = CreateObject("roByteArray") 
277: 	privateKey.fromBase64String("k3U6GLkZOoNIoSgjDshPErvqMIFdE0xMTx8kgsrhnC0=")
278: 	result = hmac.setup("sha1", privateKey)
279: 	print "result";result
280: 	if result = 0
281: 		message = CreateObject("roByteArray") 
282: 		message.fromAsciiString(msg) 
283: 		result = hmac.process(message) 
284: 		return result.toBase64String()
285: 	end if
286: End Function
/tmp/plugin/DEAAAAeOkGv7/pkg:/source/appMain.brs(278): runtime error ec: 'Dot' Operator attempted with invalid BrightScript Component or interface reference.

278: 	result = hmac.setup("sha1", privateKey)

I still have little experience with the platform so I could be missing something obvious but that makes no sense to me unless setup is not a method on the object.

thanks,
Jonny

The problem is that you named your function the same as your variable (BrightScript is case insensitive), so it thinks you’re trying to call .Setup() on your HMAC function rather than your hmac object.

Told you I was new to Roku :slightly_smiling_face: Thanks a lot, I would have taken a long time to figure that one out.

Jonny

“TheEndless” wrote:
The problem is that you named your function the same as your variable (BrightScript is case insensitive), so it thinks you’re trying to call .Setup() on your HMAC function rather than your hmac object.

“jwray” wrote:
Told you I was new to Roku :slightly_smiling_face: Thanks a lot, I would have taken a long time to figure that one out.
Jonny
It would have taken me a long time, too, if I hadn’t run into the same issue with a “configuration” object the other day. :face_with_tongue: Welcome to the platform!