Class: Lockbox::Utils
- Inherits:
-
Object
- Object
- Lockbox::Utils
- Defined in:
- lib/lockbox/utils.rb
Class Method Summary collapse
- .build_box(context, options, table, attribute) ⇒ Object
- .decode_key(key) ⇒ Object
- .encrypted_options(record, name) ⇒ Object
Class Method Details
.build_box(context, options, table, attribute) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/lockbox/utils.rb', line 3 def self.build_box(context, , table, attribute) = .except(:attribute, :encrypted_attribute, :migrating, :attached, :type, :encode) .each do |k, v| if v.is_a?(Proc) [k] = context.instance_exec(&v) if v.respond_to?(:call) elsif v.is_a?(Symbol) [k] = context.send(v) end end unless [:key] || [:encryption_key] || [:decryption_key] [:key] = Lockbox.attribute_key(table: table, attribute: attribute, master_key: .delete(:master_key)) end Lockbox.new() end |
.decode_key(key) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/lockbox/utils.rb', line 24 def self.decode_key(key) if key.encoding != Encoding::BINARY && key =~ /\A[0-9a-f]{64,128}\z/i key = [key].pack("H*") end key end |
.encrypted_options(record, name) ⇒ Object
20 21 22 |
# File 'lib/lockbox/utils.rb', line 20 def self.(record, name) record.class.respond_to?(:lockbox_attachments) && record.class.[name.to_sym] end |