Class: Karafka::Pro::Encryption::Ciphers::Base
- Inherits:
-
Object
- Object
- Karafka::Pro::Encryption::Ciphers::Base
- Defined in:
- lib/karafka/pro/encryption/ciphers/base.rb
Overview
Base for the cipher implementations, providing shared access to the configured RSA key material with per-version private key resolution
Instance Method Summary collapse
-
#initialize ⇒ Base
constructor
Initializes the cipher with an empty private keys cache.
-
#warmup(encryption_config) ⇒ Object
Eagerly parses the given encryption config key material into the instance caches.
Constructor Details
#initialize ⇒ Base
Each cipher instance holds its own tiny cache of parsed pem objects. With two cipher implementations composed by Karafka::Pro::Encryption::Cipher this means the material is parsed at most twice per version, which we accept over introducing a shared keyring concept
The caches are populated via #warmup during the single-threaded setup phase, so under normal operations runtime access is read-only. Should a key version appear only at runtime, the lazy population is idempotent and benign under MRI (worst case the same pem is parsed twice)
Initializes the cipher with an empty private keys cache
54 55 56 |
# File 'lib/karafka/pro/encryption/ciphers/base.rb', line 54 def initialize @private_pems = {} end |
Instance Method Details
#warmup(encryption_config) ⇒ Object
Eagerly parses the given encryption config key material into the instance caches
63 64 65 66 67 68 69 |
# File 'lib/karafka/pro/encryption/ciphers/base.rb', line 63 def warmup(encryption_config) @public_pem ||= OpenSSL::PKey::RSA.new(encryption_config.public_key) encryption_config.private_keys.each do |version, key| @private_pems[version] ||= OpenSSL::PKey::RSA.new(key) end end |