Class: Azure::Core::Auth::Signer

Inherits:
Object
  • Object
show all
Defined in:
lib/azure/core/auth/signer.rb

Overview

Public: Utility class to sign strings with HMAC-256 and then encode the signed string using Base64.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_key = Azure.config.storage_access_key) ⇒ Signer

Public: Initialize the Signer.

access_key - The access_key encoded in Base64. Defaults to the one

in the global configuration.


32
33
34
35
36
37
38
# File 'lib/azure/core/auth/signer.rb', line 32

def initialize(access_key=Azure.config.storage_access_key)
  if access_key.nil?
    raise ArgumentError, "storage access key must be provided"
  end

  @access_key = Base64.strict_decode64(access_key)
end

Instance Attribute Details

#access_keyObject (readonly)

The access key for the account



26
27
28
# File 'lib/azure/core/auth/signer.rb', line 26

def access_key
  @access_key
end

Instance Method Details

#sign(body) ⇒ Object

Public: Generate an HMAC signature.

body - The string to sign.

Returns a Base64 String signed with HMAC.



45
46
47
48
# File 'lib/azure/core/auth/signer.rb', line 45

def sign(body)
  signed = OpenSSL::HMAC.digest("sha256", access_key, body)
  Base64.strict_encode64(signed)
end