lockbox 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +1 -0
- data/lib/lockbox/model.rb +16 -9
- data/lib/lockbox/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05cf227cc78a31ce5ad67f4352196ee720d31e0f614db26089d1c5b0a17ae823
|
4
|
+
data.tar.gz: c47effd7829d2e7ffc7143d51fa6adb03ae6e11bd24f8b7048d39c2e559d5389
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79b18945ec5c492feedc8913669dde990b7849264b0ca3bc9e5a3be991656a59e5f953e414cf51108b747aa1d98687838715452824f0e38697cbe55fe0cae023
|
7
|
+
data.tar.gz: a747b3d2ebe4dd12cfafd91fb4970bd020515a8585a05d0bdd222ddbe30e6f402e596b4188c1d945bfaf6d2cb21914fddfd1199030f9ca73c61a5a02acf24b0f
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/lib/lockbox/model.rb
CHANGED
@@ -11,6 +11,8 @@ module Lockbox
|
|
11
11
|
# options[:type] = :json
|
12
12
|
# when Hash
|
13
13
|
# options[:type] = :hash
|
14
|
+
# when Array
|
15
|
+
# options[:type] = :array
|
14
16
|
# when String
|
15
17
|
# options[:type] = :string
|
16
18
|
# when Integer
|
@@ -20,7 +22,7 @@ module Lockbox
|
|
20
22
|
# end
|
21
23
|
|
22
24
|
custom_type = options[:type].respond_to?(:serialize) && options[:type].respond_to?(:deserialize)
|
23
|
-
raise ArgumentError, "Unknown type: #{options[:type]}" unless custom_type || [nil, :string, :boolean, :date, :datetime, :time, :integer, :float, :binary, :json, :hash].include?(options[:type])
|
25
|
+
raise ArgumentError, "Unknown type: #{options[:type]}" unless custom_type || [nil, :string, :boolean, :date, :datetime, :time, :integer, :float, :binary, :json, :hash, :array].include?(options[:type])
|
24
26
|
|
25
27
|
activerecord = defined?(ActiveRecord::Base) && self < ActiveRecord::Base
|
26
28
|
raise ArgumentError, "Type not supported yet with Mongoid" if options[:type] && !activerecord
|
@@ -112,7 +114,7 @@ module Lockbox
|
|
112
114
|
if options[:type]
|
113
115
|
attribute_type =
|
114
116
|
case options[:type]
|
115
|
-
when :json, :hash
|
117
|
+
when :json, :hash, :array
|
116
118
|
:string
|
117
119
|
when :integer
|
118
120
|
ActiveModel::Type::Integer.new(limit: 8)
|
@@ -124,6 +126,7 @@ module Lockbox
|
|
124
126
|
|
125
127
|
serialize name, JSON if options[:type] == :json
|
126
128
|
serialize name, Hash if options[:type] == :hash
|
129
|
+
serialize name, Array if options[:type] == :array
|
127
130
|
elsif !attributes_to_define_after_schema_loads.key?(name.to_s)
|
128
131
|
# when migrating it's best to specify the type directly
|
129
132
|
# however, we can try to use the original type if its already defined
|
@@ -223,19 +226,23 @@ module Lockbox
|
|
223
226
|
define_method(name) do
|
224
227
|
message = super()
|
225
228
|
|
226
|
-
|
229
|
+
# possibly keep track of decrypted attributes directly in the future
|
230
|
+
# Hash serializer returns {} when nil, Array serializer returns [] when nil
|
231
|
+
# check for this explicitly as a layer of safety
|
232
|
+
if message.nil? || ((message == {} || message == []) && activerecord && @attributes[name.to_s].value_before_type_cast.nil?)
|
227
233
|
ciphertext = send(encrypted_attribute)
|
228
234
|
message = self.class.send(decrypt_method_name, ciphertext, context: self)
|
229
235
|
|
230
236
|
if activerecord
|
231
|
-
# set previous attribute
|
232
|
-
if
|
233
|
-
|
234
|
-
|
237
|
+
# set previous attribute so changes populate correctly
|
238
|
+
# it's fine if this is set on future decryptions (as is the case when message is nil)
|
239
|
+
# as only the first value is loaded into changes
|
240
|
+
@attributes[name.to_s].instance_variable_set("@value_before_type_cast", message)
|
235
241
|
|
236
242
|
# cache
|
237
|
-
|
238
|
-
|
243
|
+
# decrypt method does type casting
|
244
|
+
if respond_to?(:write_attribute_without_type_cast, true)
|
245
|
+
write_attribute_without_type_cast(name, message) if !@attributes.frozen?
|
239
246
|
else
|
240
247
|
raw_write_attribute(name, message) if !@attributes.frozen?
|
241
248
|
end
|
data/lib/lockbox/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lockbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|