Sha256: 5a3912f31de297c8c301c726a946d877352bbdccc2e9cad81a57b81a50ff5968

Contents?: true

Size: 595 Bytes

Versions: 8

Compression:

Stored size: 595 Bytes

Contents

module Fog
  class HMAC

    def initialize(type, key)
      @key = key
      case type
      when 'sha1'
        setup_sha1
      when 'sha256'
        setup_sha256
      end
    end

    def sign(data)
      @signer.call(data)
    end

    private

    def setup_sha1
      @digest = OpenSSL::Digest.new('sha1')
      @signer = lambda do |data|
        OpenSSL::HMAC.digest(@digest, @key, data)
      end
    end

    def setup_sha256
      @digest = OpenSSL::Digest.new('sha256')
      @signer = lambda do |data|
        OpenSSL::HMAC.digest(@digest, @key, data)
      end
    end

  end
end

Version data entries

8 entries across 8 versions & 3 rubygems

Version Path
fog-core-1.24.0 lib/fog/core/hmac.rb
fog-core-1.23.0 lib/fog/core/hmac.rb
fog-core-1.22.0 lib/fog/core/hmac.rb
fog-core-1.21.1 lib/fog/core/hmac.rb
fog-maestrodev-1.20.0.20140305101839 lib/fog/core/hmac.rb
fog-maestrodev-1.20.0.20140305101305 lib/fog/core/hmac.rb
fog-core-1.21.0 lib/fog/core/hmac.rb
fog-1.20.0 lib/fog/core/hmac.rb