Sha256: 1951c2c87113e9000291fb6fd4c2cf32856c5cb5b47ee4408e680be4ba510fe0

Contents?: true

Size: 741 Bytes

Versions: 7

Compression:

Stored size: 741 Bytes

Contents

require 'crypt_keeper/log_subscriber/postgres_pgp'

module CryptKeeper
  module Provider
    class PostgresBase < Base
      include CryptKeeper::Helper::SQL
      include CryptKeeper::LogSubscriber::PostgresPgp

      INVALID_DATA_ERROR = "Wrong key or corrupt data".freeze

      # Public: Checks if value is already encrypted.
      #
      # Returns boolean
      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
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
crypt_keeper-2.3.0 lib/crypt_keeper/provider/postgres_base.rb
crypt_keeper-2.2.0 lib/crypt_keeper/provider/postgres_base.rb
crypt_keeper-2.1.0 lib/crypt_keeper/provider/postgres_base.rb
crypt_keeper-2.0.1 lib/crypt_keeper/provider/postgres_base.rb
crypt_keeper-2.0.0.rc2 lib/crypt_keeper/provider/postgres_base.rb
crypt_keeper-2.0.0.rc1 lib/crypt_keeper/provider/postgres_base.rb
crypt_keeper-1.1.1 lib/crypt_keeper/provider/postgres_base.rb