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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b1676e34ca9367ec4cfd3c655d263d23082243196abe8f0a174318383f7d4b1
4
- data.tar.gz: cdda6ac4e9dccc4ab48a67e3628212fdde369a99639cc93e569d0d623f5ab8f3
3
+ metadata.gz: 38b7a0b301adce103c1acebfa412c7a0657f687416fe237d19b02756b7019285
4
+ data.tar.gz: 17a67fabef8fdab72e2821750e95caf99db70f8d35d4fc6e75033d05e93e4c4b
5
5
  SHA512:
6
- metadata.gz: 9e747bb720312daedcb2db5458d919cb50e554b03ee04d219a3b1c2f40ca917815a066dfd767b075046f29e387d5d48a734c193a3a2c48927b5abf6e0daaa099
7
- data.tar.gz: 2a456f05d61ecc75dfdc76aca15df194b58f91d701a28d12d3b27cc40f93f301244e4f60d506f7deae7a1b6a53afab087205aaced37a54af75f81810934ed8af
6
+ metadata.gz: 5fae42738060a5ab6a0f8d3dca97703e025dd1a131d474ea807fefa251d88e0ff1098c09993420f55480cb3469c26db5abfe21d93f53ddb23b920aad162bc6f6
7
+ data.tar.gz: a24973afcb9f2ec6aad8a5219f23493fcc821d760e6f3fc602bf97c98e60ef05de33461f95cef188452c474bd54b7be3694c050eaea52b50548f5d08f325b56d
@@ -1,3 +1,9 @@
1
+ ## 0.4.5 (2020-06-26)
2
+
3
+ - Improved error message for non-string values
4
+ - Fixed error with migrating Action Text
5
+ - Fixed error with migrating serialized attributes
6
+
1
7
  ## 0.4.4 (2020-06-23)
2
8
 
3
9
  - Added support for `pluck`
@@ -13,7 +13,7 @@ module Lockbox
13
13
  end
14
14
 
15
15
  def encrypt(message, **options)
16
- message = check_string(message, "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, "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, name)
69
+ def check_string(str)
70
70
  str = str.read if str.respond_to?(:read)
71
- raise TypeError, "can't convert #{name} to string" unless str.respond_to?(:to_str)
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
 
@@ -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
- type = (try(:attribute_types) || {})[name.to_s]
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
- type = (try(:attribute_types) || {})[name.to_s]
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
@@ -1,3 +1,3 @@
1
1
  module Lockbox
2
- VERSION = "0.4.4"
2
+ VERSION = "0.4.5"
3
3
  end
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
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-24 00:00:00.000000000 Z
11
+ date: 2020-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler