Class: SimpleSigner

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_signer/signer.rb

Class Method Summary collapse

Class Method Details

.escape(token) ⇒ Object



32
33
34
# File 'lib/simple_signer/signer.rb', line 32

def self.escape token
  token.empty? ? token : CGI.escape(token)
end

.sign(options = {}) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/simple_signer/signer.rb', line 23

def self.sign options = {}
  raise 'secret_key is required!' unless options.include?(:secret_key) and options[:secret_key]
  raise 'string is required!'     unless options.include?(:string)     and options[:string]

  signed = OpenSSL::HMAC.digest('sha1', options[:secret_key], options[:string].encode('utf-8'))

  Base64.encode64(signed).strip
end

.unescape(token) ⇒ Object



36
37
38
# File 'lib/simple_signer/signer.rb', line 36

def self.unescape token
  (token.empty? or not token.include?('%')) ? token : CGI.unescape(token)
end