go_secure 0.63 → 0.65
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/go_secure.rb +91 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c524e2e840ee7893bffe1419b602ef0b658d09a
|
4
|
+
data.tar.gz: f0d4e9a0f459d919b03fa7e546452f63c2ab2db9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fb801b6017a0c7680b1d3e1f14f4d9f53be4cadca882688091fff56f1d75403f3f91fb2fa2e5e4cbbd27862583b1895e459e069aa074b6b70cd675d6eb46ba7
|
7
|
+
data.tar.gz: 7c4183402268648b01df8cebb16642f687abd6335911abe9dda79145a4bc1d3ae6f5587f5c15ea2fe0e415ab7362d0a3c54e44e0fef4a8a27bed9574694ab67e
|
data/lib/go_secure.rb
CHANGED
@@ -157,4 +157,95 @@ module GoSecure
|
|
157
157
|
end
|
158
158
|
end
|
159
159
|
end
|
160
|
+
|
161
|
+
module SerializeInstanceMethods
|
162
|
+
def load_secure_object
|
163
|
+
@secure_object_json = nil.to_json
|
164
|
+
if self.id
|
165
|
+
attr = read_attribute(self.class.secure_column) || (!self.respond_to?(:secure_column_value) && self.send(self.class.secure_column)) || (@secure_object.is_a?(String) && @secure_object) || nil
|
166
|
+
if attr && attr.match(/\s*^{/)
|
167
|
+
@secure_object = JSON.parse(attr)
|
168
|
+
else
|
169
|
+
@secure_object = GoSecure::SecureJson.load(attr)
|
170
|
+
end
|
171
|
+
@secure_object_json = @secure_object.to_json
|
172
|
+
@loaded_secure_object = true
|
173
|
+
end
|
174
|
+
true
|
175
|
+
end
|
176
|
+
|
177
|
+
# If the serialized data has changed since initialize and paper_trail
|
178
|
+
# is configured, then we need to manually mark the column as dirty
|
179
|
+
# to make sure a proper paper_trail is maintained
|
180
|
+
def mark_changed_secure_object_hash
|
181
|
+
if !send("#{self.class.secure_column}_changed?")
|
182
|
+
json = @secure_object.to_json
|
183
|
+
if json != @secure_object_json
|
184
|
+
send("#{self.class.secure_column}_will_change!")
|
185
|
+
end
|
186
|
+
end
|
187
|
+
true
|
188
|
+
end
|
189
|
+
|
190
|
+
def persist_secure_object
|
191
|
+
self.class.more_before_saves ||= []
|
192
|
+
self.class.more_before_saves.each do |method|
|
193
|
+
res = send(method)
|
194
|
+
return false if res == false
|
195
|
+
end
|
196
|
+
mark_changed_secure_object_hash
|
197
|
+
if send("#{self.class.secure_column}_changed?")
|
198
|
+
secure = GoSecure::SecureJson.dump(@secure_object)
|
199
|
+
@secure_object = GoSecure::SecureJson.load(secure)
|
200
|
+
write_attribute(self.class.secure_column, secure)
|
201
|
+
end
|
202
|
+
true
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
module SerializeClassMethods
|
207
|
+
def secure_serialize(column)
|
208
|
+
raise "only one secure column per record! (yes I'm lazy)" if self.respond_to?(:secure_column) && self.secure_column
|
209
|
+
cattr_accessor :secure_column
|
210
|
+
cattr_accessor :more_before_saves
|
211
|
+
self.secure_column = column
|
212
|
+
prepend SecureSerializeHelpers
|
213
|
+
|
214
|
+
before_save :persist_secure_object
|
215
|
+
define_singleton_method(:before_save) do |*args|
|
216
|
+
raise "only simple before_save calls after secure_serialize: #{args.to_json}" unless args.length == 1 && args[0].is_a?(Symbol)
|
217
|
+
self.more_before_saves ||= []
|
218
|
+
self.more_before_saves << args[0]
|
219
|
+
end
|
220
|
+
define_method("secure_column_value") do
|
221
|
+
nil
|
222
|
+
end
|
223
|
+
define_method("#{column}") do
|
224
|
+
load_secure_object unless @loaded_secure_object
|
225
|
+
@secure_object
|
226
|
+
end
|
227
|
+
define_method("#{column}=") do |val|
|
228
|
+
@loaded_secure_object = true
|
229
|
+
@secure_object = val
|
230
|
+
end
|
231
|
+
# Commented out because eager-loading an encrypted data column is not efficient
|
232
|
+
# after_initialize :load_secure_object
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
module SecureSerializeHelpers
|
237
|
+
def reload(*args)
|
238
|
+
res = super
|
239
|
+
load_secure_object
|
240
|
+
res
|
241
|
+
end
|
242
|
+
|
243
|
+
def []=(*args)
|
244
|
+
if args[0].to_s == self.class.secure_column
|
245
|
+
send("#{self.class.secure_column}=", args[1])
|
246
|
+
else
|
247
|
+
super
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
160
251
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: go_secure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.65'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Whitmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|