Class: Mushikago::Auth::Signer

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

Overview

署名を作成するクラス

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(secret_key) ⇒ Signer

Returns a new instance of Signer.

Parameters:

  • secret_key (String)

    シークレットキー



13
14
15
# File 'lib/mushikago/auth/signer.rb', line 13

def initialize secret_key
  @secret_key = secret_key
end

Instance Attribute Details

#secret_keyString (readonly)

Returns シークレットキー.

Returns:

  • (String)

    シークレットキー



10
11
12
# File 'lib/mushikago/auth/signer.rb', line 10

def secret_key
  @secret_key
end

Instance Method Details

#sign(string_to_sign, digest_method = 'sha256') ⇒ String

Returns 署名.

Parameters:

  • string_to_sign (String)

    署名の元になる文字列

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

    署名作成のアルゴリズム

Returns:

  • (String)

    署名



20
21
22
23
24
25
26
27
28
# File 'lib/mushikago/auth/signer.rb', line 20

def sign(string_to_sign, digest_method='sha256')
  Base64.encode64(
    OpenSSL::HMAC.digest(
      OpenSSL::Digest::Digest.new(digest_method),
      secret_key,
      string_to_sign
    )
  ).strip
end