Class: ConcernsOnRails::Encryption::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/concerns_on_rails/encryption.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



43
44
45
46
47
48
# File 'lib/concerns_on_rails/encryption.rb', line 43

def initialize
  @key = nil
  @key_derivation_salt = DEFAULT_KDF_SALT
  @on_missing_key = :raise
  @raise_on_decrypt_error = true
end

Instance Attribute Details

#keyObject

key: raw 32-byte binary, 64-hex, passphrase, or a Proc returning one. key_derivation_salt: PBKDF2 salt (part of key identity — keep stable). on_missing_key: :raise (default) or :passthrough (dev/test escape hatch that stores/reads plaintext when no key is configured — never in prod). raise_on_decrypt_error: true (default) raises DecryptionError on a bad read; false returns nil (a narrow reporting-path opt-out, less safe).



41
42
43
# File 'lib/concerns_on_rails/encryption.rb', line 41

def key
  @key
end

#key_derivation_saltObject

key: raw 32-byte binary, 64-hex, passphrase, or a Proc returning one. key_derivation_salt: PBKDF2 salt (part of key identity — keep stable). on_missing_key: :raise (default) or :passthrough (dev/test escape hatch that stores/reads plaintext when no key is configured — never in prod). raise_on_decrypt_error: true (default) raises DecryptionError on a bad read; false returns nil (a narrow reporting-path opt-out, less safe).



41
42
43
# File 'lib/concerns_on_rails/encryption.rb', line 41

def key_derivation_salt
  @key_derivation_salt
end

#on_missing_keyObject

key: raw 32-byte binary, 64-hex, passphrase, or a Proc returning one. key_derivation_salt: PBKDF2 salt (part of key identity — keep stable). on_missing_key: :raise (default) or :passthrough (dev/test escape hatch that stores/reads plaintext when no key is configured — never in prod). raise_on_decrypt_error: true (default) raises DecryptionError on a bad read; false returns nil (a narrow reporting-path opt-out, less safe).



41
42
43
# File 'lib/concerns_on_rails/encryption.rb', line 41

def on_missing_key
  @on_missing_key
end

#raise_on_decrypt_errorObject

key: raw 32-byte binary, 64-hex, passphrase, or a Proc returning one. key_derivation_salt: PBKDF2 salt (part of key identity — keep stable). on_missing_key: :raise (default) or :passthrough (dev/test escape hatch that stores/reads plaintext when no key is configured — never in prod). raise_on_decrypt_error: true (default) raises DecryptionError on a bad read; false returns nil (a narrow reporting-path opt-out, less safe).



41
42
43
# File 'lib/concerns_on_rails/encryption.rb', line 41

def raise_on_decrypt_error
  @raise_on_decrypt_error
end

Instance Method Details

#key?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/concerns_on_rails/encryption.rb', line 60

def key?
  !key_material.nil?
end

#key_materialObject

Resolve the configured key (calling a Proc) to raw String material, or nil when unset. Callers decide raise-vs-passthrough from that nil.



52
53
54
55
56
57
58
# File 'lib/concerns_on_rails/encryption.rb', line 52

def key_material
  material = key.respond_to?(:call) ? key.call : key
  return nil if material.nil?

  material = material.to_s
  material.empty? ? nil : material
end