Module: PqcRails::ActiveRecord::Context
- Defined in:
- lib/pqc_rails/active_record/context.rb
Overview
ActiveRecord::Encryptionのデフォルトcontextに、PqcRails::Cipherと PqcRails::ActiveRecord::KeyProviderを設定する。
注意: ActiveRecord::Encryption.config.custom_contexts はwith_encryption_context用の スレッドローカルな一時上書きスタックで、永続的な差し替えには使えない。 永続的な差し替えの正しい入口は ActiveRecord::Encryption.configure(...)。
Class Method Summary collapse
-
.existing_config_value(name) ⇒ Object
ActiveRecord::Encryption.configure(...)は呼ぶたびにprimary_key/deterministic_key/ key_derivation_saltを常に上書きする(未指定ならnilで巻き戻す)ため、install!を呼ぶ前に bin/rails db:encryption:init等で既に設定されていた値を、明示的な指定が無い限り 引き継ぐ。config側の値は未設定だとErrors::Configurationを送出しうるので握りつぶす。.
- .install!(pq_alg_name: PqcRails::Cipher::DEFAULT_PQ_ALG_NAME, primary_key: existing_config_value(:primary_key), deterministic_key: existing_config_value(:deterministic_key), key_derivation_salt: existing_config_value(:key_derivation_salt)) ⇒ Object
Class Method Details
.existing_config_value(name) ⇒ Object
ActiveRecord::Encryption.configure(...)は呼ぶたびにprimary_key/deterministic_key/ key_derivation_saltを常に上書きする(未指定ならnilで巻き戻す)ため、install!を呼ぶ前に bin/rails db:encryption:init等で既に設定されていた値を、明示的な指定が無い限り 引き継ぐ。config側の値は未設定だとErrors::Configurationを送出しうるので握りつぶす。
35 36 37 38 39 |
# File 'lib/pqc_rails/active_record/context.rb', line 35 def existing_config_value(name) ::ActiveRecord::Encryption.config.public_send(name) rescue ::ActiveRecord::Encryption::Errors::Configuration nil end |
.install!(pq_alg_name: PqcRails::Cipher::DEFAULT_PQ_ALG_NAME, primary_key: existing_config_value(:primary_key), deterministic_key: existing_config_value(:deterministic_key), key_derivation_salt: existing_config_value(:key_derivation_salt)) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pqc_rails/active_record/context.rb', line 18 def install!(pq_alg_name: PqcRails::Cipher::DEFAULT_PQ_ALG_NAME, primary_key: existing_config_value(:primary_key), deterministic_key: existing_config_value(:deterministic_key), key_derivation_salt: existing_config_value(:key_derivation_salt)) ::ActiveRecord::Encryption.configure( key_provider: PqcRails::ActiveRecord::KeyProvider.new, cipher: PqcRails::Cipher.new(pq_alg_name: pq_alg_name), primary_key: primary_key, deterministic_key: deterministic_key, key_derivation_salt: key_derivation_salt ) end |