Class: CryptKeeper::Provider::PostgresPgpPublicKey
- Inherits:
-
PostgresBase
- Object
- Base
- PostgresBase
- CryptKeeper::Provider::PostgresPgpPublicKey
- Defined in:
- lib/crypt_keeper/provider/postgres_pgp_public_key.rb
Constant Summary
Constants inherited from PostgresBase
CryptKeeper::Provider::PostgresBase::INVALID_DATA_ERROR
Constants included from LogSubscriber::PostgresPgp
LogSubscriber::PostgresPgp::FILTER
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
-
#decrypt(value) ⇒ Object
Public: Decrypts a string.
-
#encrypt(value) ⇒ Object
Public: Encrypts a string.
-
#initialize(options = {}) ⇒ PostgresPgpPublicKey
constructor
A new instance of PostgresPgpPublicKey.
Methods inherited from PostgresBase
Methods included from LogSubscriber::PostgresPgp
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ PostgresPgpPublicKey
Returns a new instance of PostgresPgpPublicKey.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/crypt_keeper/provider/postgres_pgp_public_key.rb', line 6 def initialize( = {}) ::ActiveSupport.run_load_hooks(:crypt_keeper_postgres_pgp_log, self) @key = .fetch(:key) do raise ArgumentError, "Missing :key" end @public_key = .fetch(:public_key) @private_key = [:private_key] end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
4 5 6 |
# File 'lib/crypt_keeper/provider/postgres_pgp_public_key.rb', line 4 def key @key end |
Instance Method Details
#decrypt(value) ⇒ Object
Public: Decrypts a string
Returns a plaintext string
31 32 33 34 35 36 37 38 |
# File 'lib/crypt_keeper/provider/postgres_pgp_public_key.rb', line 31 def decrypt(value) if @private_key.present? && encrypted?(value) escape_and_execute_sql(["SELECT pgp_pub_decrypt(?, dearmor(?), ?)", value, @private_key, @key])['pgp_pub_decrypt'] else value end end |
#encrypt(value) ⇒ Object
Public: Encrypts a string
Returns an encrypted string
20 21 22 23 24 25 26 |
# File 'lib/crypt_keeper/provider/postgres_pgp_public_key.rb', line 20 def encrypt(value) if !@private_key.present? && encrypted?(value) value else escape_and_execute_sql(["SELECT pgp_pub_encrypt(?, dearmor(?))", value.to_s, @public_key])['pgp_pub_encrypt'] end end |