Class: ActiverecordCursorPagination::SqlSigner

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord_cursor_pagination/sql_signer.rb

Instance Method Summary collapse

Instance Method Details

#sign(sql) ⇒ String

Sign SQL

Parameters:

  • sql (ActiveRecord::Relation, nil)

    The SQL to sign.

Returns:

  • (String)

    The signature hash.



10
11
12
13
14
15
16
17
18
# File 'lib/activerecord_cursor_pagination/sql_signer.rb', line 10

def sign(sql)
  return nil if sql.nil?

  sql = format sql
  digest = OpenSSL::Digest.new 'sha1'
  hmac = OpenSSL::HMAC.digest digest, secret_key, sql
  hash = Base64.encode64 hmac
  hash.gsub /\n+/, ""
end