crypt_keeper 0.6.1 → 0.7.0
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.
- data/crypt_keeper.gemspec +1 -1
- data/gemfiles/activerecord_3_0.gemfile.lock +4 -4
- data/gemfiles/activerecord_3_1.gemfile.lock +4 -4
- data/gemfiles/activerecord_3_2.gemfile.lock +4 -4
- data/lib/crypt_keeper/model.rb +18 -14
- data/lib/crypt_keeper/version.rb +1 -1
- data/spec/model_spec.rb +4 -2
- metadata +5 -5
data/crypt_keeper.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
|
|
17
17
|
|
18
18
|
gem.add_runtime_dependency 'activerecord', '>= 3.0'
|
19
19
|
gem.add_runtime_dependency 'activesupport', '>= 3.0'
|
20
|
-
gem.add_runtime_dependency 'appraisal', '~> 0.
|
20
|
+
gem.add_runtime_dependency 'appraisal', '~> 0.5.1'
|
21
21
|
|
22
22
|
gem.add_development_dependency 'rspec', '~> 2.11.0'
|
23
23
|
gem.add_development_dependency 'guard', '~> 1.3.0'
|
@@ -1,10 +1,10 @@
|
|
1
1
|
PATH
|
2
|
-
remote: /
|
2
|
+
remote: /Users/justin/work/Personal/crypt_keeper
|
3
3
|
specs:
|
4
|
-
crypt_keeper (0.
|
4
|
+
crypt_keeper (0.6.1)
|
5
5
|
activerecord (>= 3.0)
|
6
6
|
activesupport (>= 3.0)
|
7
|
-
appraisal (~> 0.
|
7
|
+
appraisal (~> 0.5.1)
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
@@ -20,7 +20,7 @@ GEM
|
|
20
20
|
activesupport (3.2.7)
|
21
21
|
i18n (~> 0.6)
|
22
22
|
multi_json (~> 1.0)
|
23
|
-
appraisal (0.
|
23
|
+
appraisal (0.5.1)
|
24
24
|
bundler
|
25
25
|
rake
|
26
26
|
arel (3.0.2)
|
@@ -1,10 +1,10 @@
|
|
1
1
|
PATH
|
2
|
-
remote: /
|
2
|
+
remote: /Users/justin/work/Personal/crypt_keeper
|
3
3
|
specs:
|
4
|
-
crypt_keeper (0.
|
4
|
+
crypt_keeper (0.6.1)
|
5
5
|
activerecord (>= 3.0)
|
6
6
|
activesupport (>= 3.0)
|
7
|
-
appraisal (~> 0.
|
7
|
+
appraisal (~> 0.5.1)
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
@@ -20,7 +20,7 @@ GEM
|
|
20
20
|
activesupport (3.2.7)
|
21
21
|
i18n (~> 0.6)
|
22
22
|
multi_json (~> 1.0)
|
23
|
-
appraisal (0.
|
23
|
+
appraisal (0.5.1)
|
24
24
|
bundler
|
25
25
|
rake
|
26
26
|
arel (3.0.2)
|
@@ -1,10 +1,10 @@
|
|
1
1
|
PATH
|
2
|
-
remote: /
|
2
|
+
remote: /Users/justin/work/Personal/crypt_keeper
|
3
3
|
specs:
|
4
|
-
crypt_keeper (0.
|
4
|
+
crypt_keeper (0.6.1)
|
5
5
|
activerecord (>= 3.0)
|
6
6
|
activesupport (>= 3.0)
|
7
|
-
appraisal (~> 0.
|
7
|
+
appraisal (~> 0.5.1)
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
@@ -20,7 +20,7 @@ GEM
|
|
20
20
|
activesupport (3.2.7)
|
21
21
|
i18n (~> 0.6)
|
22
22
|
multi_json (~> 1.0)
|
23
|
-
appraisal (0.
|
23
|
+
appraisal (0.5.1)
|
24
24
|
bundler
|
25
25
|
rake
|
26
26
|
arel (3.0.2)
|
data/lib/crypt_keeper/model.rb
CHANGED
@@ -5,6 +5,16 @@ module CryptKeeper
|
|
5
5
|
module Model
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
|
+
# Public: Ensures that each field exist and is of type text. This prevents
|
9
|
+
# encrypted data from being truncated.
|
10
|
+
def ensure_valid_field!(field)
|
11
|
+
if self.class.columns_hash["#{field}"].nil?
|
12
|
+
raise ArgumentError, "Column :#{field} does not exist"
|
13
|
+
elsif self.class.columns_hash["#{field}"].type != :text
|
14
|
+
raise ArgumentError, "Column :#{field} must be of type 'text' to be used for encryption"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
8
18
|
private
|
9
19
|
|
10
20
|
# Private: Encrypt each crypt_keeper_fields
|
@@ -25,6 +35,13 @@ module CryptKeeper
|
|
25
35
|
end
|
26
36
|
end
|
27
37
|
|
38
|
+
# Private: Run each crypt_keeper_fields through ensure_valid_field!
|
39
|
+
def enforce_column_types_callback
|
40
|
+
crypt_keeper_fields.each do |field|
|
41
|
+
ensure_valid_field! field
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
28
45
|
module ClassMethods
|
29
46
|
# Public: Setup fields for encryption
|
30
47
|
#
|
@@ -86,20 +103,7 @@ module CryptKeeper
|
|
86
103
|
after_save :decrypt_callback
|
87
104
|
after_find :decrypt_callback
|
88
105
|
before_save :encrypt_callback
|
89
|
-
|
90
|
-
crypt_keeper_fields.each do |field|
|
91
|
-
ensure_valid_field! field
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
# Private: Ensures that each field exist and is of type text. This prevents
|
96
|
-
# encrypted data from being truncated.
|
97
|
-
def ensure_valid_field!(field)
|
98
|
-
if columns_hash["#{field}"].nil?
|
99
|
-
raise ArgumentError, "Column :#{field} does not exist"
|
100
|
-
elsif columns_hash["#{field}"].type != :text
|
101
|
-
raise ArgumentError, "Column :#{field} must be of type 'text' to be used for encryption"
|
102
|
-
end
|
106
|
+
before_save :enforce_column_types_callback
|
103
107
|
end
|
104
108
|
end
|
105
109
|
end
|
data/lib/crypt_keeper/version.rb
CHANGED
data/spec/model_spec.rb
CHANGED
@@ -20,12 +20,14 @@ module CryptKeeper
|
|
20
20
|
|
21
21
|
it "should raise an exception with missing field" do
|
22
22
|
msg = "Column :none does not exist"
|
23
|
-
|
23
|
+
subject.crypt_keeper :none, encryptor: :fake_encryptor
|
24
|
+
expect { subject.new.save }.to raise_error(ArgumentError, msg)
|
24
25
|
end
|
25
26
|
|
26
27
|
it "should raise an exception with wrong field type" do
|
27
28
|
msg = "Column :name must be of type 'text' to be used for encryption"
|
28
|
-
|
29
|
+
subject.crypt_keeper :name, encryptor: :fake_encryptor
|
30
|
+
expect { subject.new.save }.to raise_error(ArgumentError, msg)
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crypt_keeper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -50,7 +50,7 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0.
|
53
|
+
version: 0.5.1
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,7 +58,7 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
61
|
+
version: 0.5.1
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: rspec
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -227,7 +227,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
227
227
|
version: '0'
|
228
228
|
segments:
|
229
229
|
- 0
|
230
|
-
hash:
|
230
|
+
hash: 1508799386363054050
|
231
231
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
232
232
|
none: false
|
233
233
|
requirements:
|
@@ -236,7 +236,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
236
236
|
version: '0'
|
237
237
|
segments:
|
238
238
|
- 0
|
239
|
-
hash:
|
239
|
+
hash: 1508799386363054050
|
240
240
|
requirements: []
|
241
241
|
rubyforge_project:
|
242
242
|
rubygems_version: 1.8.23
|