lockbox 0.4.4 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/lockbox/encryptor.rb +5 -4
- data/lib/lockbox/model.rb +8 -2
- 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: 38b7a0b301adce103c1acebfa412c7a0657f687416fe237d19b02756b7019285
|
4
|
+
data.tar.gz: 17a67fabef8fdab72e2821750e95caf99db70f8d35d4fc6e75033d05e93e4c4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fae42738060a5ab6a0f8d3dca97703e025dd1a131d474ea807fefa251d88e0ff1098c09993420f55480cb3469c26db5abfe21d93f53ddb23b920aad162bc6f6
|
7
|
+
data.tar.gz: a24973afcb9f2ec6aad8a5219f23493fcc821d760e6f3fc602bf97c98e60ef05de33461f95cef188452c474bd54b7be3694c050eaea52b50548f5d08f325b56d
|
data/CHANGELOG.md
CHANGED
data/lib/lockbox/encryptor.rb
CHANGED
@@ -13,7 +13,7 @@ module Lockbox
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def encrypt(message, **options)
|
16
|
-
message = check_string(message
|
16
|
+
message = check_string(message)
|
17
17
|
ciphertext = @boxes.first.encrypt(message, **options)
|
18
18
|
ciphertext = Base64.strict_encode64(ciphertext) if @encode
|
19
19
|
ciphertext
|
@@ -21,7 +21,7 @@ module Lockbox
|
|
21
21
|
|
22
22
|
def decrypt(ciphertext, **options)
|
23
23
|
ciphertext = Base64.decode64(ciphertext) if @encode
|
24
|
-
ciphertext = check_string(ciphertext
|
24
|
+
ciphertext = check_string(ciphertext)
|
25
25
|
|
26
26
|
# ensure binary
|
27
27
|
if ciphertext.encoding != Encoding::BINARY
|
@@ -66,9 +66,10 @@ module Lockbox
|
|
66
66
|
|
67
67
|
private
|
68
68
|
|
69
|
-
def check_string(str
|
69
|
+
def check_string(str)
|
70
70
|
str = str.read if str.respond_to?(:read)
|
71
|
-
|
71
|
+
# Ruby uses "no implicit conversion of Object into String"
|
72
|
+
raise TypeError, "can't convert #{str.class.name} to String" unless str.respond_to?(:to_str)
|
72
73
|
str.to_str
|
73
74
|
end
|
74
75
|
|
data/lib/lockbox/model.rb
CHANGED
@@ -146,6 +146,10 @@ module Lockbox
|
|
146
146
|
# however, we can try to use the original type if its already defined
|
147
147
|
if attributes_to_define_after_schema_loads.key?(original_name.to_s)
|
148
148
|
attribute name, attributes_to_define_after_schema_loads[original_name.to_s].first
|
149
|
+
elsif options[:migrating]
|
150
|
+
# we use the original attribute for serialization in the encrypt and decrypt methods
|
151
|
+
# so we can use a generic value here
|
152
|
+
attribute name, ActiveRecord::Type::Value.new
|
149
153
|
else
|
150
154
|
attribute name, :string
|
151
155
|
end
|
@@ -319,7 +323,8 @@ module Lockbox
|
|
319
323
|
# do nothing
|
320
324
|
# encrypt will convert to binary
|
321
325
|
else
|
322
|
-
|
326
|
+
# use original name for serialized attributes
|
327
|
+
type = (try(:attribute_types) || {})[original_name.to_s]
|
323
328
|
message = type.serialize(message) if type
|
324
329
|
end
|
325
330
|
end
|
@@ -361,7 +366,8 @@ module Lockbox
|
|
361
366
|
# do nothing
|
362
367
|
# decrypt returns binary string
|
363
368
|
else
|
364
|
-
|
369
|
+
# use original name for serialized attributes
|
370
|
+
type = (try(:attribute_types) || {})[original_name.to_s]
|
365
371
|
message = type.deserialize(message) if type
|
366
372
|
message.force_encoding(Encoding::UTF_8) if !type || type.is_a?(ActiveModel::Type::String)
|
367
373
|
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.4.
|
4
|
+
version: 0.4.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-06-
|
11
|
+
date: 2020-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|