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

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

Overview

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) ⇒ Signer

Initialize the Signer.

Parameters:

  • access_key (String)

    The access_key encoded in Base64.


30
31
32
33
34
35
36
# File 'lib/azure/storage/core/auth/signer.rb', line 30

def initialize(access_key)
  if access_key.nil?
    raise ArgumentError, 'Signing 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


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

def access_key
  @access_key
end

Instance Method Details

#sign(body) ⇒ String

Generate an HMAC signature.

Parameters:

  • body (String)

    The string to sign.

Returns:

  • (String)

    a Base64 String signed with HMAC.


43
44
45
46
# File 'lib/azure/storage/core/auth/signer.rb', line 43

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