Module: Familia::Features::EncryptedFields::ModelClassMethods
- Defined in:
- lib/familia/features/encrypted_fields.rb
Instance Method Summary collapse
-
#encrypted_field(name, aad_fields: [], algorithm: nil) ⇒ Object
Define an encrypted field that transparently encrypts/decrypts values.
-
#encrypted_field?(field_name) ⇒ Boolean
Check if a field is encrypted.
-
#encrypted_fields ⇒ Array<Symbol>
Returns list of encrypted field names defined on this class.
-
#encryption_info ⇒ Hash
Get encryption algorithm information.
Instance Method Details
#encrypted_field(name, aad_fields: [], algorithm: nil) ⇒ Object
Define an encrypted field that transparently encrypts/decrypts values
Encrypted fields are stored as JSON objects containing the encrypted ciphertext along with cryptographic metadata. Values are automatically encrypted on assignment and decrypted on access.
335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/familia/features/encrypted_fields.rb', line 335 def encrypted_field(name, aad_fields: [], algorithm: nil, **) @encrypted_fields ||= [] @encrypted_fields << name unless @encrypted_fields.include?(name) # Add to field_groups if the group exists if field_groups&.key?(:encrypted_fields) field_groups[:encrypted_fields] << name end field_type = EncryptedFieldType.new(name, aad_fields: aad_fields, algorithm: algorithm, **) register_field_type(field_type) end |
#encrypted_field?(field_name) ⇒ Boolean
Check if a field is encrypted
361 362 363 |
# File 'lib/familia/features/encrypted_fields.rb', line 361 def encrypted_field?(field_name) encrypted_fields.include?(field_name.to_sym) end |
#encrypted_fields ⇒ Array<Symbol>
Returns list of encrypted field names defined on this class
352 353 354 |
# File 'lib/familia/features/encrypted_fields.rb', line 352 def encrypted_fields @encrypted_fields || [] end |
#encryption_info ⇒ Hash
Get encryption algorithm information
369 370 371 372 373 374 375 376 377 |
# File 'lib/familia/features/encrypted_fields.rb', line 369 def encryption_info provider = Familia::Encryption.current_provider { algorithm: provider.algorithm_name, key_size: provider.key_size, nonce_size: provider.nonce_size, tag_size: provider.tag_size, } end |