mmangino/facebooker2 — Issue #73: undefined method `reset_key' for nil:NilClass
Author: Thorsson
Created: 2011-12-14 11:28:20+00:00
State: open

I have just updated to latest Facebooker2 version and got this error when i am trying to use current_facebook_user, i have made some inspection and went down to discover what is going wrong. So here is what i've discovered:

```ruby
def Base.digest(key, text)
begin
hmac = self.new(key)
hmac.update(text)
hmac.digest
ensure
hmac.reset_key
end
end
```

hmac is nil in ensure because it is never set
and if i go to see what new method does is use set_key(key) in the same class which is doing xor operation on Facebook secret key. So if I try to test this new instance in console and send over Facebook secret key i get this error message

NoMethodError: undefined method `^' for "6":String
from /Users/ivanturkovic/.rvm/gems/ruby-1.9.2-p290@spda/gems/ruby-hmac-0.3.2/lib/hmac.rb:49:in `block in set_key'
from /Users/ivanturkovic/.rvm/gems/ruby-1.9.2-p290@spda/gems/ruby-hmac-0.3.2/lib/hmac.rb:48:in `each'
from /Users/ivanturkovic/.rvm/gems/ruby-1.9.2-p290@spda/gems/ruby-hmac-0.3.2/lib/hmac.rb:48:in `set_key'
from /Users/ivanturkovic/.rvm/gems/ruby-1.9.2-p290@spda/gems/ruby-hmac-0.3.2/lib/hmac.rb:30:in `initialize'
from /Users/ivanturkovic/.rvm/gems/ruby-1.9.2-p290@spda/gems/ruby-hmac-0.3.2/lib/hmac-sha2.rb:7:in `initialize'
from (irb):12:in `new'

It seems that Facebook secret key is being used xor operation on a string which makes hmac nil and raises an exception so when it is in ensure block the hmac is still nil.

Did you came with this problem before?