symmetric-encryption 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c30cffd6db15e542fee8493edb838e9843906d54
4
- data.tar.gz: 9e869eb73ce3cba78ff656d049fe3177fdeadea4
3
+ metadata.gz: e317defa3d42505af60cafe4a0b2536eece87610
4
+ data.tar.gz: 457e73b4600877ccb94491bac705fe2d5cb07b8b
5
5
  SHA512:
6
- metadata.gz: 2caf1f8d69a160d78c372d61d0c2267e58416ab470ad955f7a6d2e7a381798649d68ff054dd3065a318bfb510aa86606bd4e609061bd602ac3cf7486b505294a
7
- data.tar.gz: 0cd59f67247763283ae7320971477a064489b5a551fd15fa0e14f12cb8d56ec4d6a8e479b28bd6cf94a1396f3cb10aee9ad3f551f7cb266e0cd5baf7f1948734
6
+ metadata.gz: 628ef9f9873e93d96d276775033524d2f40744e289760be21f7e9c3c2bdaf99f8b65af5313e7c3d8c2e6a861ef4d49918695733ff62420728d1fe0628407f9b3
7
+ data.tar.gz: a94058c40a5f285a7dc78207cceb980546cdd09dfcfe90fc11a28c727029868d50b63183c7cceee03d1d9f741b939ab73293484b5984fb3a71edc841bb40f0d9
@@ -392,7 +392,7 @@ module SymmetricEncryption
392
392
  openssl_cipher.iv = iv if iv
393
393
  # Set the binary indicator on the header if string is Binary Encoded
394
394
  binary = (string.encoding == SymmetricEncryption::BINARY_ENCODING)
395
- self.class.build_header(version, compress, random_iv ? iv : nil, binary) +
395
+ self.class.build_header(version, compress, random_iv ? iv : nil, nil, nil, binary) +
396
396
  openssl_cipher.update(compress ? Zlib::Deflate.deflate(string) : string)
397
397
  else
398
398
  openssl_cipher.iv = @iv if @iv
@@ -79,13 +79,13 @@
79
79
  Mongoid::Fields.option :encrypted do |model, field, options|
80
80
  if options != false
81
81
  options = options.is_a?(Hash) ? options.dup : {}
82
- field_name = field.name
82
+ encrypted_field_name = field.name
83
83
 
84
- decrypt_as = options.delete(:decrypt_as)
85
- if decrypt_as.nil? && field_name.to_s.start_with?('encrypted_')
86
- decrypt_as = field_name.to_s['encrypted_'.length..-1]
84
+ decrypted_field_name = options.delete(:decrypt_as)
85
+ if decrypted_field_name.nil? && encrypted_field_name.to_s.start_with?('encrypted_')
86
+ decrypted_field_name = encrypted_field_name.to_s['encrypted_'.length..-1]
87
87
  else
88
- raise "SymmetricEncryption for Mongoid. Encryption enabled for field #{field_name}. It must either start with 'encrypted_' or the option :decrypt_as must be supplied"
88
+ raise "SymmetricEncryption for Mongoid. Encryption enabled for field #{encrypted_field_name}. It must either start with 'encrypted_' or the option :decrypt_as must be supplied"
89
89
  end
90
90
 
91
91
  random_iv = options.delete(:random_iv) || false
@@ -95,21 +95,21 @@ Mongoid::Fields.option :encrypted do |model, field, options|
95
95
  model.class_eval(<<-EOS, __FILE__, __LINE__ + 1)
96
96
  # Set the un-encrypted field
97
97
  # Also updates the encrypted field with the encrypted value
98
- def #{decrypt_as}=(value)
99
- @stored_#{field_name} = ::SymmetricEncryption.encrypt(value,#{random_iv},#{compress})
100
- self.#{field_name} = @stored_#{field_name}
101
- @#{decrypt_as} = value.freeze
98
+ # Freeze the decrypted field value so that it is not modified directly
99
+ def #{decrypted_field_name}=(value)
100
+ self.#{encrypted_field_name} = @stored_#{encrypted_field_name} = ::SymmetricEncryption.encrypt(value,#{random_iv},#{compress})
101
+ @#{decrypted_field_name} = value.freeze
102
102
  end
103
103
 
104
104
  # Returns the decrypted value for the encrypted field
105
105
  # The decrypted value is cached and is only decrypted if the encrypted value has changed
106
106
  # If this method is not called, then the encrypted value is never decrypted
107
- def #{decrypt_as}
108
- if @stored_#{field_name} != self.#{field_name}
109
- @#{decrypt_as} = ::SymmetricEncryption.decrypt(self.#{field_name}).freeze
110
- @stored_#{field_name} = self.#{field_name}
107
+ def #{decrypted_field_name}
108
+ if @stored_#{encrypted_field_name} != self.#{encrypted_field_name}
109
+ @#{decrypted_field_name} = ::SymmetricEncryption.decrypt(self.#{encrypted_field_name}).freeze
110
+ @stored_#{encrypted_field_name} = self.#{encrypted_field_name}
111
111
  end
112
- @#{decrypt_as}
112
+ @#{decrypted_field_name}
113
113
  end
114
114
  EOS
115
115
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module SymmetricEncryption #:nodoc
3
- VERSION = "3.0.1"
3
+ VERSION = "3.0.2"
4
4
  end
data/test/test_db.sqlite3 CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: symmetric-encryption
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison