Class: CryptKeeper::Provider::PostgresBase

Inherits:
Base
  • Object
show all
Includes:
Helper::SQL, LogSubscriber::PostgresPgp
Defined in:
lib/crypt_keeper/provider/postgres_base.rb

Direct Known Subclasses

PostgresPgp, PostgresPgpPublicKey

Constant Summary collapse

INVALID_DATA_ERROR =
"Wrong key or corrupt data".freeze

Constants included from LogSubscriber::PostgresPgp

LogSubscriber::PostgresPgp::FILTER

Instance Method Summary collapse

Methods included from LogSubscriber::PostgresPgp

#sql

Methods inherited from Base

#dump, #load

Instance Method Details

#encrypted?(value) ⇒ Boolean

Public: Checks if value is already encrypted.

Returns boolean

Returns:

  • (Boolean)

14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/crypt_keeper/provider/postgres_base.rb', line 14

def encrypted?(value)
  begin
    escape_and_execute_sql(["SELECT pgp_key_id(?)", value.to_s],
      new_transaction: true)['pgp_key_id'].present?
  rescue ActiveRecord::StatementInvalid => e
    if e.message.include?(INVALID_DATA_ERROR)
      false
    else
      raise
    end
  end
end