Class: Vufer::Signature
- Inherits:
-
Object
- Object
- Vufer::Signature
- Defined in:
- lib/vufer/signature.rb
Constant Summary collapse
- HEX_DIGEST =
'd41d8cd98f00b204e9800998ecf8427e'.freeze
Class Method Summary collapse
-
.generate(path, body, verb, time) ⇒ String
Generates the signature based on path, body, http verb and time.
Class Method Details
.generate(path, body, verb, time) ⇒ String
Generates the signature based on path, body, http verb and time.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vufer/signature.rb', line 23 def generate(path, body, verb, time) raise KeyEnvironmentError if Vufer.access_key.empty? || Vufer.secret_key.empty? hex_digest = HEX_DIGEST content_type = '' if verb == 'POST' || verb == 'PUT' content_type = 'application/json' hex_digest = Digest::MD5.hexdigest(body.to_json) end to_digest = "#{verb}\n#{hex_digest}\n#{content_type}\n#{time}\n#{path}" Base64.encode64( OpenSSL::HMAC.digest( OpenSSL::Digest::SHA1.new, Vufer.secret_key, to_digest ) ) end |