attr_keyring 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +7 -7
- data/lib/attr_keyring.rb +14 -2
- data/lib/attr_keyring/active_record.rb +7 -6
- data/lib/attr_keyring/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: 4a80344a57c60c546692d38f9d117129a9ad8f6ab796247de5a6188bbdddbd7a
|
4
|
+
data.tar.gz: 5842f654124fcd2de9c409b3464ff36b029a79dc19f2be973fabafb316f139ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a734ba2ae31db2ee0875d1cde94184a389f319242f01bce6cce70b561ba14e7075c7926dd8b82bd313bacbcdbb8148e7ddf2f91a46a532065e85d79a18db4fd7
|
7
|
+
data.tar.gz: 47499f9c934a7956588586c27fb07a6a913d8d658ee46a3d6b8d619af2e8df2af4a4d2fdc01cf6e749139c774d0aabe8ecac51ab6ff0d6b9e0e9f32821b97416
|
data/Gemfile.lock
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
attr_keyring (0.2.
|
4
|
+
attr_keyring (0.2.2)
|
5
5
|
activerecord
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (5.2.
|
11
|
-
activesupport (= 5.2.
|
12
|
-
activerecord (5.2.
|
13
|
-
activemodel (= 5.2.
|
14
|
-
activesupport (= 5.2.
|
10
|
+
activemodel (5.2.2)
|
11
|
+
activesupport (= 5.2.2)
|
12
|
+
activerecord (5.2.2)
|
13
|
+
activemodel (= 5.2.2)
|
14
|
+
activesupport (= 5.2.2)
|
15
15
|
arel (>= 9.0)
|
16
|
-
activesupport (5.2.
|
16
|
+
activesupport (5.2.2)
|
17
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
18
|
i18n (>= 0.7, < 2)
|
19
19
|
minitest (~> 5.1)
|
data/lib/attr_keyring.rb
CHANGED
@@ -19,9 +19,21 @@ module AttrKeyring
|
|
19
19
|
extend AttrKeyring::ActiveRecord::ClassMethods
|
20
20
|
include AttrKeyring::ActiveRecord::InstanceMethods
|
21
21
|
|
22
|
-
|
22
|
+
class << self
|
23
|
+
attr_accessor :keyring_attrs
|
24
|
+
attr_accessor :keyring
|
25
|
+
|
26
|
+
def inherited(subclass)
|
27
|
+
super
|
28
|
+
|
29
|
+
subclass.keyring_attrs = []
|
30
|
+
subclass.keyring = Keyring.new({})
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
23
34
|
cattr_accessor :keyring_column_name, default: "keyring_id"
|
24
|
-
|
35
|
+
self.keyring_attrs = []
|
36
|
+
self.keyring = Keyring.new({})
|
25
37
|
|
26
38
|
before_save :migrate_to_latest_encryption_key
|
27
39
|
end
|
@@ -6,6 +6,7 @@ module AttrKeyring
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def attr_encrypt(*attributes)
|
9
|
+
self.keyring_attrs ||= []
|
9
10
|
keyring_attrs.push(*attributes)
|
10
11
|
|
11
12
|
attributes.each do |attribute|
|
@@ -19,8 +20,8 @@ module AttrKeyring
|
|
19
20
|
return attr_reset_column(attribute) if value.nil?
|
20
21
|
|
21
22
|
stored_keyring_id = public_send(keyring_column_name)
|
22
|
-
keyring_id = stored_keyring_id || keyring.current_key&.id
|
23
|
-
encrypted_value = keyring.encrypt(value, keyring_id)
|
23
|
+
keyring_id = stored_keyring_id || self.class.keyring.current_key&.id
|
24
|
+
encrypted_value = self.class.keyring.encrypt(value, keyring_id)
|
24
25
|
|
25
26
|
public_send("#{keyring_column_name}=", keyring_id) unless stored_keyring_id
|
26
27
|
public_send("encrypted_#{attribute}=", encrypted_value)
|
@@ -35,7 +36,7 @@ module AttrKeyring
|
|
35
36
|
return unless encrypted_value
|
36
37
|
|
37
38
|
keyring_id = public_send(keyring_column_name)
|
38
|
-
keyring.decrypt(encrypted_value, keyring_id)
|
39
|
+
self.class.keyring.decrypt(encrypted_value, keyring_id)
|
39
40
|
end
|
40
41
|
end
|
41
42
|
end
|
@@ -53,11 +54,11 @@ module AttrKeyring
|
|
53
54
|
end
|
54
55
|
|
55
56
|
private def migrate_to_latest_encryption_key
|
56
|
-
keyring_id = keyring.current_key.id
|
57
|
+
keyring_id = self.class.keyring.current_key.id
|
57
58
|
|
58
|
-
keyring_attrs.each do |attribute|
|
59
|
+
self.class.keyring_attrs.each do |attribute|
|
59
60
|
value = public_send(attribute)
|
60
|
-
encrypted_value = keyring.encrypt(value, keyring_id)
|
61
|
+
encrypted_value = self.class.keyring.encrypt(value, keyring_id)
|
61
62
|
|
62
63
|
public_send("encrypted_#{attribute}=", encrypted_value)
|
63
64
|
attr_encrypt_digest(attribute, value)
|
data/lib/attr_keyring/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attr_keyring
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|