Module: AWS::Core::Signer

Defined in:
lib/aws/core/signer.rb

Overview

This module provides a #sign method that accepts a secret and a string to sign.

Class Method Summary collapse

Class Method Details

.hmac(key, value, digest = 'sha256') ⇒ String

Computes an HMAC digest of the passed string.

Parameters:

  • key (String)
  • value (String)
  • digest (String) (defaults to: 'sha256')

    (‘sha256’)

Returns:

  • (String)


39
40
41
# File 'lib/aws/core/signer.rb', line 39

def hmac key, value, digest = 'sha256'
  OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new(digest), key, value)
end

.sign(secret, string_to_sign, digest_method = 'sha256') ⇒ String

Signs a string using the credentials stored in memory.

Parameters:

  • secret (String)

    Usually an AWS secret access key.

  • string_to_sign (String)

    The string to sign.

  • digest_method (String) (defaults to: 'sha256')

    The digest method to use when computing the HMAC digest.

Returns:

  • (String)

    Returns the computed signature.



29
30
31
# File 'lib/aws/core/signer.rb', line 29

def sign secret, string_to_sign, digest_method = 'sha256'
  Base64.encode64(hmac(secret, string_to_sign, digest_method)).strip
end