Module: CouchbaseOrm::Encrypt
- Included in:
- Document, Persistence
- Defined in:
- lib/couchbase-orm/encrypt.rb
Instance Method Summary collapse
Instance Method Details
#decode_encrypted_attributes(attributes) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/couchbase-orm/encrypt.rb', line 23 def decode_encrypted_attributes(attributes) attributes.map do |key, value| key = key.to_s if key.start_with?('encrypted$') key = key.gsub('encrypted$', '') value = value.with_indifferent_access[:ciphertext] end [key, value] end.to_h end |
#encode_encrypted_attributes ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/couchbase-orm/encrypt.rb', line 6 def encode_encrypted_attributes attributes.map do |key, value| type = self.class.attribute_types[key.to_s] if type.is_a?(CouchbaseOrm::Types::Encrypted) next unless value raise "Can not serialize value #{value} of type '#{value.class}' for Tanker encrypted attribute" unless value.is_a?(String) ["encrypted$#{key}", { alg: type.alg, ciphertext: value }] else [key, value] end end.compact.to_h end |