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 +4 -4
- data/lib/symmetric_encryption/cipher.rb +1 -1
- data/lib/symmetric_encryption/mongoid.rb +14 -14
- data/lib/symmetric_encryption/version.rb +1 -1
- data/test/test_db.sqlite3 +0 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e317defa3d42505af60cafe4a0b2536eece87610
|
4
|
+
data.tar.gz: 457e73b4600877ccb94491bac705fe2d5cb07b8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
82
|
+
encrypted_field_name = field.name
|
83
83
|
|
84
|
-
|
85
|
-
if
|
86
|
-
|
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 #{
|
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
|
-
|
99
|
-
|
100
|
-
self.#{
|
101
|
-
@#{
|
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 #{
|
108
|
-
if @stored_#{
|
109
|
-
@#{
|
110
|
-
@stored_#{
|
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
|
-
@#{
|
112
|
+
@#{decrypted_field_name}
|
113
113
|
end
|
114
114
|
EOS
|
115
115
|
end
|
data/test/test_db.sqlite3
CHANGED
Binary file
|