Sha256: fe92258bfcc57b075d3a27ea48c6166b826c792f7782993109f249f8407b870d

Contents?: true

Size: 864 Bytes

Versions: 18

Compression:

Stored size: 864 Bytes

Contents

# frozen_string_literal: true

module LedgerSync
  module Util
    class Signer
      HMAC_SHA1_DIGEST   = OpenSSL::Digest.new('sha1')
      HMAC_SHA256_DIGEST = OpenSSL::Digest.new('sha256')

      attr_reader :str

      def initialize(str:)
        @str = str
      end

      def hmac_sha1(key:, escape: false)
        ret = Base64.encode64(OpenSSL::HMAC.digest(HMAC_SHA1_DIGEST, key, str)).strip
        ret = self.class.escape(str: ret) if escape
        ret
      end

      def hmac_sha256(key:, escape: false)
        ret = Base64.encode64(OpenSSL::HMAC.digest(HMAC_SHA256_DIGEST, key, str)).strip
        ret = self.class.escape(str: ret) if escape
        ret
      end

      def self.escape(str:)
        CGI.escape(str).gsub(/\+/, '%20')
      end

      def self.unescape(str:)
        CGI.unescape(str.gsub(/%20/, '+'))
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
ledger_sync-2.6.0 lib/ledger_sync/util/signer.rb
ledger_sync-2.5.0 lib/ledger_sync/util/signer.rb
ledger_sync-2.4.4 lib/ledger_sync/util/signer.rb
ledger_sync-2.3.1 lib/ledger_sync/util/signer.rb
ledger_sync-2.2.3 lib/ledger_sync/util/signer.rb
ledger_sync-2.2.1 lib/ledger_sync/util/signer.rb
ledger_sync-2.2.0 lib/ledger_sync/util/signer.rb
ledger_sync-2.0.2 lib/ledger_sync/util/signer.rb
ledger_sync-2.0.1 lib/ledger_sync/util/signer.rb
ledger_sync-2.0.0 lib/ledger_sync/util/signer.rb
ledger_sync-2.0.0.pre.1 lib/ledger_sync/util/signer.rb
ledger_sync-1.8.1 lib/ledger_sync/util/signer.rb
ledger_sync-1.8.0 lib/ledger_sync/util/signer.rb
ledger_sync-1.7.0 lib/ledger_sync/util/signer.rb
ledger_sync-1.6.0 lib/ledger_sync/util/signer.rb
ledger_sync-1.5.2 lib/ledger_sync/util/signer.rb
ledger_sync-1.5.1 lib/ledger_sync/util/signer.rb
ledger_sync-1.5.0 lib/ledger_sync/util/signer.rb