crypt_keeper 0.13.1 → 0.14.0.pre

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/.travis.yml CHANGED
@@ -5,6 +5,8 @@ gemfile:
5
5
  - gemfiles/activerecord_3_1.gemfile
6
6
  - gemfiles/activerecord_3_2.gemfile
7
7
  - gemfiles/activerecord_4_0.gemfile
8
+ before_install:
9
+ - bundle install
8
10
  before_script:
9
11
  - cp spec/default.database.yml spec/database.yml
10
12
  - psql -c 'CREATE DATABASE crypt_keeper_providers;' -U postgres
@@ -18,9 +20,4 @@ notifications:
18
20
  on_failure: always
19
21
  rvm:
20
22
  - 1.9.3
21
- - jruby
22
- matrix:
23
- allow_failures:
24
- - rvm: jruby
25
- env:
26
- - JRUBY_OPTS=--1.9
23
+ - 2.0.0
data/Appraisals CHANGED
@@ -14,6 +14,6 @@ appraise "activerecord_3_2" do
14
14
  end
15
15
 
16
16
  appraise "activerecord_4_0" do
17
- gem 'activerecord', '~> 4.0.0.beta1'
18
- gem 'activesupport', '~> 4.0.0.beta1'
17
+ gem 'activerecord', '~> 4.0.0'
18
+ gem 'activesupport', '~> 4.0.0'
19
19
  end
data/crypt_keeper.gemspec CHANGED
@@ -7,6 +7,7 @@ Gem::Specification.new do |gem|
7
7
  gem.description = %q{Transparent encryption for ActiveRecord that isn't over-engineered}
8
8
  gem.summary = gem.description
9
9
  gem.homepage = "http://jmazzi.github.com/crypt_keeper/"
10
+ gem.license = 'MIT'
10
11
 
11
12
  gem.files = `git ls-files`.split($\)
12
13
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -15,8 +16,8 @@ Gem::Specification.new do |gem|
15
16
  gem.require_paths = ["lib"]
16
17
  gem.version = CryptKeeper::VERSION
17
18
 
18
- gem.add_runtime_dependency 'activerecord', '>= 3.0'
19
- gem.add_runtime_dependency 'activesupport', '>= 3.0'
19
+ gem.add_runtime_dependency 'activerecord', '>= 3.0', '< 4.1'
20
+ gem.add_runtime_dependency 'activesupport', '>= 3.0', '< 4.1'
20
21
 
21
22
  gem.add_development_dependency 'rspec', '~> 2.13.0'
22
23
  gem.add_development_dependency 'guard', '~> 1.8.0'
@@ -1,23 +1,23 @@
1
1
  PATH
2
2
  remote: /Users/justin/work/jmazzi/crypt_keeper
3
3
  specs:
4
- crypt_keeper (0.13.1)
5
- activerecord (>= 3.0)
6
- activesupport (>= 3.0)
4
+ crypt_keeper (0.14.0)
5
+ activerecord (>= 3.0, < 4.1)
6
+ activesupport (>= 3.0, < 4.1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (3.2.13)
12
- activesupport (= 3.2.13)
11
+ activemodel (3.2.14)
12
+ activesupport (= 3.2.14)
13
13
  builder (~> 3.0.0)
14
- activerecord (3.2.13)
15
- activemodel (= 3.2.13)
16
- activesupport (= 3.2.13)
14
+ activerecord (3.2.14)
15
+ activemodel (= 3.2.14)
16
+ activesupport (= 3.2.14)
17
17
  arel (~> 3.0.2)
18
18
  tzinfo (~> 0.3.29)
19
- activesupport (3.2.13)
20
- i18n (= 0.6.1)
19
+ activesupport (3.2.14)
20
+ i18n (~> 0.6, >= 0.6.4)
21
21
  multi_json (~> 1.0)
22
22
  appraisal (0.5.2)
23
23
  bundler
@@ -26,17 +26,16 @@ GEM
26
26
  builder (3.0.4)
27
27
  coderay (1.0.9)
28
28
  colorize (0.5.8)
29
- coveralls (0.6.6)
29
+ coveralls (0.6.7)
30
30
  colorize
31
31
  multi_json (~> 1.3)
32
32
  rest-client
33
33
  simplecov (>= 0.7)
34
34
  thor
35
35
  diff-lcs (1.2.4)
36
- ffi (1.8.1)
37
- ffi (1.8.1-java)
36
+ ffi (1.9.0)
38
37
  formatador (0.2.4)
39
- guard (1.8.0)
38
+ guard (1.8.2)
40
39
  formatador (>= 0.2.4)
41
40
  listen (>= 1.0.0)
42
41
  lumberjack (>= 1.0.2)
@@ -45,29 +44,24 @@ GEM
45
44
  guard-rspec (2.5.4)
46
45
  guard (>= 1.1)
47
46
  rspec (~> 2.11)
48
- i18n (0.6.1)
49
- listen (1.0.2)
47
+ i18n (0.6.5)
48
+ listen (1.3.0)
50
49
  rb-fsevent (>= 0.9.3)
51
50
  rb-inotify (>= 0.9)
52
51
  rb-kqueue (>= 0.2)
53
- lumberjack (1.0.3)
54
- method_source (0.8.1)
55
- mime-types (1.23)
56
- multi_json (1.7.2)
57
- mysql2 (0.3.11)
52
+ lumberjack (1.0.4)
53
+ method_source (0.8.2)
54
+ mime-types (1.24)
55
+ multi_json (1.7.9)
56
+ mysql2 (0.3.13)
58
57
  pg (0.15.1)
59
- pry (0.9.12.1)
58
+ pry (0.9.12.2)
60
59
  coderay (~> 1.0.5)
61
60
  method_source (~> 0.8)
62
61
  slop (~> 3.4)
63
- pry (0.9.12.1-java)
64
- coderay (~> 1.0.5)
65
- method_source (~> 0.8)
66
- slop (~> 3.4)
67
- spoon (~> 0.0)
68
62
  rake (10.0.4)
69
63
  rb-fsevent (0.9.3)
70
- rb-inotify (0.9.0)
64
+ rb-inotify (0.9.1)
71
65
  ffi (>= 0.5.0)
72
66
  rb-kqueue (0.2.0)
73
67
  ffi (>= 0.5.0)
@@ -85,15 +79,12 @@ GEM
85
79
  multi_json (~> 1.0)
86
80
  simplecov-html (~> 0.7.1)
87
81
  simplecov-html (0.7.1)
88
- slop (3.4.4)
89
- spoon (0.0.3)
90
- ffi
91
- sqlite3 (1.3.7)
82
+ slop (3.4.6)
83
+ sqlite3 (1.3.8)
92
84
  thor (0.18.1)
93
85
  tzinfo (0.3.37)
94
86
 
95
87
  PLATFORMS
96
- java
97
88
  ruby
98
89
 
99
90
  DEPENDENCIES
@@ -1,23 +1,23 @@
1
1
  PATH
2
2
  remote: /Users/justin/work/jmazzi/crypt_keeper
3
3
  specs:
4
- crypt_keeper (0.13.1)
5
- activerecord (>= 3.0)
6
- activesupport (>= 3.0)
4
+ crypt_keeper (0.14.0)
5
+ activerecord (>= 3.0, < 4.1)
6
+ activesupport (>= 3.0, < 4.1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (3.2.13)
12
- activesupport (= 3.2.13)
11
+ activemodel (3.2.14)
12
+ activesupport (= 3.2.14)
13
13
  builder (~> 3.0.0)
14
- activerecord (3.2.13)
15
- activemodel (= 3.2.13)
16
- activesupport (= 3.2.13)
14
+ activerecord (3.2.14)
15
+ activemodel (= 3.2.14)
16
+ activesupport (= 3.2.14)
17
17
  arel (~> 3.0.2)
18
18
  tzinfo (~> 0.3.29)
19
- activesupport (3.2.13)
20
- i18n (= 0.6.1)
19
+ activesupport (3.2.14)
20
+ i18n (~> 0.6, >= 0.6.4)
21
21
  multi_json (~> 1.0)
22
22
  appraisal (0.5.2)
23
23
  bundler
@@ -26,17 +26,16 @@ GEM
26
26
  builder (3.0.4)
27
27
  coderay (1.0.9)
28
28
  colorize (0.5.8)
29
- coveralls (0.6.6)
29
+ coveralls (0.6.7)
30
30
  colorize
31
31
  multi_json (~> 1.3)
32
32
  rest-client
33
33
  simplecov (>= 0.7)
34
34
  thor
35
35
  diff-lcs (1.2.4)
36
- ffi (1.8.1)
37
- ffi (1.8.1-java)
36
+ ffi (1.9.0)
38
37
  formatador (0.2.4)
39
- guard (1.8.0)
38
+ guard (1.8.2)
40
39
  formatador (>= 0.2.4)
41
40
  listen (>= 1.0.0)
42
41
  lumberjack (>= 1.0.2)
@@ -45,29 +44,24 @@ GEM
45
44
  guard-rspec (2.5.4)
46
45
  guard (>= 1.1)
47
46
  rspec (~> 2.11)
48
- i18n (0.6.1)
49
- listen (1.0.2)
47
+ i18n (0.6.5)
48
+ listen (1.3.0)
50
49
  rb-fsevent (>= 0.9.3)
51
50
  rb-inotify (>= 0.9)
52
51
  rb-kqueue (>= 0.2)
53
- lumberjack (1.0.3)
54
- method_source (0.8.1)
55
- mime-types (1.23)
56
- multi_json (1.7.2)
57
- mysql2 (0.3.11)
52
+ lumberjack (1.0.4)
53
+ method_source (0.8.2)
54
+ mime-types (1.24)
55
+ multi_json (1.7.9)
56
+ mysql2 (0.3.13)
58
57
  pg (0.15.1)
59
- pry (0.9.12.1)
58
+ pry (0.9.12.2)
60
59
  coderay (~> 1.0.5)
61
60
  method_source (~> 0.8)
62
61
  slop (~> 3.4)
63
- pry (0.9.12.1-java)
64
- coderay (~> 1.0.5)
65
- method_source (~> 0.8)
66
- slop (~> 3.4)
67
- spoon (~> 0.0)
68
62
  rake (10.0.4)
69
63
  rb-fsevent (0.9.3)
70
- rb-inotify (0.9.0)
64
+ rb-inotify (0.9.1)
71
65
  ffi (>= 0.5.0)
72
66
  rb-kqueue (0.2.0)
73
67
  ffi (>= 0.5.0)
@@ -85,15 +79,12 @@ GEM
85
79
  multi_json (~> 1.0)
86
80
  simplecov-html (~> 0.7.1)
87
81
  simplecov-html (0.7.1)
88
- slop (3.4.4)
89
- spoon (0.0.3)
90
- ffi
91
- sqlite3 (1.3.7)
82
+ slop (3.4.6)
83
+ sqlite3 (1.3.8)
92
84
  thor (0.18.1)
93
85
  tzinfo (0.3.37)
94
86
 
95
87
  PLATFORMS
96
- java
97
88
  ruby
98
89
 
99
90
  DEPENDENCIES
@@ -1,23 +1,23 @@
1
1
  PATH
2
2
  remote: /Users/justin/work/jmazzi/crypt_keeper
3
3
  specs:
4
- crypt_keeper (0.13.1)
5
- activerecord (>= 3.0)
6
- activesupport (>= 3.0)
4
+ crypt_keeper (0.14.0)
5
+ activerecord (>= 3.0, < 4.1)
6
+ activesupport (>= 3.0, < 4.1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (3.2.13)
12
- activesupport (= 3.2.13)
11
+ activemodel (3.2.14)
12
+ activesupport (= 3.2.14)
13
13
  builder (~> 3.0.0)
14
- activerecord (3.2.13)
15
- activemodel (= 3.2.13)
16
- activesupport (= 3.2.13)
14
+ activerecord (3.2.14)
15
+ activemodel (= 3.2.14)
16
+ activesupport (= 3.2.14)
17
17
  arel (~> 3.0.2)
18
18
  tzinfo (~> 0.3.29)
19
- activesupport (3.2.13)
20
- i18n (= 0.6.1)
19
+ activesupport (3.2.14)
20
+ i18n (~> 0.6, >= 0.6.4)
21
21
  multi_json (~> 1.0)
22
22
  appraisal (0.5.2)
23
23
  bundler
@@ -26,17 +26,16 @@ GEM
26
26
  builder (3.0.4)
27
27
  coderay (1.0.9)
28
28
  colorize (0.5.8)
29
- coveralls (0.6.6)
29
+ coveralls (0.6.7)
30
30
  colorize
31
31
  multi_json (~> 1.3)
32
32
  rest-client
33
33
  simplecov (>= 0.7)
34
34
  thor
35
35
  diff-lcs (1.2.4)
36
- ffi (1.8.1)
37
- ffi (1.8.1-java)
36
+ ffi (1.9.0)
38
37
  formatador (0.2.4)
39
- guard (1.8.0)
38
+ guard (1.8.2)
40
39
  formatador (>= 0.2.4)
41
40
  listen (>= 1.0.0)
42
41
  lumberjack (>= 1.0.2)
@@ -45,29 +44,24 @@ GEM
45
44
  guard-rspec (2.5.4)
46
45
  guard (>= 1.1)
47
46
  rspec (~> 2.11)
48
- i18n (0.6.1)
49
- listen (1.0.2)
47
+ i18n (0.6.5)
48
+ listen (1.3.0)
50
49
  rb-fsevent (>= 0.9.3)
51
50
  rb-inotify (>= 0.9)
52
51
  rb-kqueue (>= 0.2)
53
- lumberjack (1.0.3)
54
- method_source (0.8.1)
55
- mime-types (1.23)
56
- multi_json (1.7.2)
57
- mysql2 (0.3.11)
52
+ lumberjack (1.0.4)
53
+ method_source (0.8.2)
54
+ mime-types (1.24)
55
+ multi_json (1.7.9)
56
+ mysql2 (0.3.13)
58
57
  pg (0.15.1)
59
- pry (0.9.12.1)
58
+ pry (0.9.12.2)
60
59
  coderay (~> 1.0.5)
61
60
  method_source (~> 0.8)
62
61
  slop (~> 3.4)
63
- pry (0.9.12.1-java)
64
- coderay (~> 1.0.5)
65
- method_source (~> 0.8)
66
- slop (~> 3.4)
67
- spoon (~> 0.0)
68
62
  rake (10.0.4)
69
63
  rb-fsevent (0.9.3)
70
- rb-inotify (0.9.0)
64
+ rb-inotify (0.9.1)
71
65
  ffi (>= 0.5.0)
72
66
  rb-kqueue (0.2.0)
73
67
  ffi (>= 0.5.0)
@@ -85,15 +79,12 @@ GEM
85
79
  multi_json (~> 1.0)
86
80
  simplecov-html (~> 0.7.1)
87
81
  simplecov-html (0.7.1)
88
- slop (3.4.4)
89
- spoon (0.0.3)
90
- ffi
91
- sqlite3 (1.3.7)
82
+ slop (3.4.6)
83
+ sqlite3 (1.3.8)
92
84
  thor (0.18.1)
93
85
  tzinfo (0.3.37)
94
86
 
95
87
  PLATFORMS
96
- java
97
88
  ruby
98
89
 
99
90
  DEPENDENCIES
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 4.0.0.beta1"
6
- gem "activesupport", "~> 4.0.0.beta1"
5
+ gem "activerecord", "~> 4.0.0"
6
+ gem "activesupport", "~> 4.0.0"
7
7
 
8
8
  gemspec :path=>"../"
@@ -1,48 +1,46 @@
1
1
  PATH
2
2
  remote: /Users/justin/work/jmazzi/crypt_keeper
3
3
  specs:
4
- crypt_keeper (0.13.1)
5
- activerecord (>= 3.0)
6
- activesupport (>= 3.0)
4
+ crypt_keeper (0.14.0)
5
+ activerecord (>= 3.0, < 4.1)
6
+ activesupport (>= 3.0, < 4.1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (4.0.0.beta1)
12
- activesupport (= 4.0.0.beta1)
11
+ activemodel (4.0.0)
12
+ activesupport (= 4.0.0)
13
13
  builder (~> 3.1.0)
14
- activerecord (4.0.0.beta1)
15
- activemodel (= 4.0.0.beta1)
16
- activerecord-deprecated_finders (~> 0.0.3)
17
- activesupport (= 4.0.0.beta1)
18
- arel (~> 4.0.0.beta1)
19
- activerecord-deprecated_finders (0.0.3)
20
- activesupport (4.0.0.beta1)
21
- i18n (~> 0.6.2)
14
+ activerecord (4.0.0)
15
+ activemodel (= 4.0.0)
16
+ activerecord-deprecated_finders (~> 1.0.2)
17
+ activesupport (= 4.0.0)
18
+ arel (~> 4.0.0)
19
+ activerecord-deprecated_finders (1.0.3)
20
+ activesupport (4.0.0)
21
+ i18n (~> 0.6, >= 0.6.4)
22
22
  minitest (~> 4.2)
23
23
  multi_json (~> 1.3)
24
24
  thread_safe (~> 0.1)
25
- tzinfo (~> 0.3.33)
25
+ tzinfo (~> 0.3.37)
26
26
  appraisal (0.5.2)
27
27
  bundler
28
28
  rake
29
- arel (4.0.0.beta2)
30
- atomic (1.0.1)
31
- atomic (1.0.1-java)
29
+ arel (4.0.0)
30
+ atomic (1.1.13)
32
31
  builder (3.1.4)
33
32
  coderay (1.0.9)
34
33
  colorize (0.5.8)
35
- coveralls (0.6.6)
34
+ coveralls (0.6.7)
36
35
  colorize
37
36
  multi_json (~> 1.3)
38
37
  rest-client
39
38
  simplecov (>= 0.7)
40
39
  thor
41
40
  diff-lcs (1.2.4)
42
- ffi (1.8.1)
43
- ffi (1.8.1-java)
41
+ ffi (1.9.0)
44
42
  formatador (0.2.4)
45
- guard (1.8.0)
43
+ guard (1.8.2)
46
44
  formatador (>= 0.2.4)
47
45
  listen (>= 1.0.0)
48
46
  lumberjack (>= 1.0.2)
@@ -51,30 +49,25 @@ GEM
51
49
  guard-rspec (2.5.4)
52
50
  guard (>= 1.1)
53
51
  rspec (~> 2.11)
54
- i18n (0.6.4)
55
- listen (1.0.2)
52
+ i18n (0.6.5)
53
+ listen (1.3.0)
56
54
  rb-fsevent (>= 0.9.3)
57
55
  rb-inotify (>= 0.9)
58
56
  rb-kqueue (>= 0.2)
59
- lumberjack (1.0.3)
60
- method_source (0.8.1)
61
- mime-types (1.23)
62
- minitest (4.7.0)
63
- multi_json (1.7.2)
64
- mysql2 (0.3.11)
57
+ lumberjack (1.0.4)
58
+ method_source (0.8.2)
59
+ mime-types (1.24)
60
+ minitest (4.7.5)
61
+ multi_json (1.7.9)
62
+ mysql2 (0.3.13)
65
63
  pg (0.15.1)
66
- pry (0.9.12.1)
64
+ pry (0.9.12.2)
67
65
  coderay (~> 1.0.5)
68
66
  method_source (~> 0.8)
69
67
  slop (~> 3.4)
70
- pry (0.9.12.1-java)
71
- coderay (~> 1.0.5)
72
- method_source (~> 0.8)
73
- slop (~> 3.4)
74
- spoon (~> 0.0)
75
68
  rake (10.0.4)
76
69
  rb-fsevent (0.9.3)
77
- rb-inotify (0.9.0)
70
+ rb-inotify (0.9.1)
78
71
  ffi (>= 0.5.0)
79
72
  rb-kqueue (0.2.0)
80
73
  ffi (>= 0.5.0)
@@ -92,22 +85,19 @@ GEM
92
85
  multi_json (~> 1.0)
93
86
  simplecov-html (~> 0.7.1)
94
87
  simplecov-html (0.7.1)
95
- slop (3.4.4)
96
- spoon (0.0.3)
97
- ffi
98
- sqlite3 (1.3.7)
88
+ slop (3.4.6)
89
+ sqlite3 (1.3.8)
99
90
  thor (0.18.1)
100
- thread_safe (0.1.0)
91
+ thread_safe (0.1.2)
101
92
  atomic
102
93
  tzinfo (0.3.37)
103
94
 
104
95
  PLATFORMS
105
- java
106
96
  ruby
107
97
 
108
98
  DEPENDENCIES
109
- activerecord (~> 4.0.0.beta1)
110
- activesupport (~> 4.0.0.beta1)
99
+ activerecord (~> 4.0.0)
100
+ activesupport (~> 4.0.0)
111
101
  appraisal (~> 0.5.2)
112
102
  coveralls
113
103
  crypt_keeper!
@@ -9,5 +9,15 @@ module CryptKeeper
9
9
  ::ActiveRecord::Base.connection.execute(query).first
10
10
  end
11
11
  end
12
+
13
+ module Serializer
14
+ def dump(value)
15
+ encrypt(value)
16
+ end
17
+
18
+ def load(value)
19
+ decrypt(value)
20
+ end
21
+ end
12
22
  end
13
23
  end
@@ -17,47 +17,6 @@ module CryptKeeper
17
17
 
18
18
  private
19
19
 
20
- # Private: A hash of encrypted attributes with their encrypted values
21
- #
22
- # Returns a Hash
23
- def crypt_keeper_dirty_tracking
24
- @crypt_keeper_dirty_tracking ||= HashWithIndifferentAccess.new
25
- end
26
-
27
- # Private: Determine if the field's plaintext value changed. It compares
28
- # it to the original value that came from the DB before decryption
29
- #
30
- # Returns boolean
31
- def plaintext_changed?(field)
32
- new_record? || self[field] != self.class.decrypt(crypt_keeper_dirty_tracking[field])
33
- end
34
-
35
- # Private: Encrypt each crypt_keeper_fields
36
- def encrypt_callback
37
- crypt_keeper_fields.each do |field|
38
- if !self[field].nil?
39
- if plaintext_changed?(field)
40
- self[field] = self.class.encrypt read_attribute(field)
41
- else
42
- self[field] = crypt_keeper_dirty_tracking[field]
43
- clear_field_changes! field
44
- end
45
- end
46
- end
47
- end
48
-
49
- # Private: Decrypt each crypt_keeper_fields
50
- def decrypt_callback
51
- crypt_keeper_fields.each do |field|
52
- if !self[field].nil?
53
- crypt_keeper_dirty_tracking[field] = read_attribute(field)
54
- self[field] = self.class.decrypt read_attribute(field)
55
- end
56
-
57
- clear_field_changes! field
58
- end
59
- end
60
-
61
20
  # Private: Run each crypt_keeper_fields through ensure_valid_field!
62
21
  def enforce_column_types_callback
63
22
  crypt_keeper_fields.each do |field|
@@ -65,15 +24,6 @@ module CryptKeeper
65
24
  end
66
25
  end
67
26
 
68
- # Private: Removes changes from `#previous_changes` and
69
- # `#changed_attributes` so the model isn't considered dirty.
70
- #
71
- # field - The field to clear
72
- def clear_field_changes!(field)
73
- previous_changes.delete(field.to_s)
74
- changed_attributes.delete(field.to_s)
75
- end
76
-
77
27
  module ClassMethods
78
28
  # Public: Setup fields for encryption
79
29
  #
@@ -89,39 +39,25 @@ module CryptKeeper
89
39
  # end
90
40
  #
91
41
  def crypt_keeper(*args)
92
- class_attribute :crypt_keeper_options
93
42
  class_attribute :crypt_keeper_fields
94
43
  class_attribute :crypt_keeper_encryptor
44
+ class_attribute :crypt_keeper_options
95
45
 
96
46
  self.crypt_keeper_options = args.extract_options!
97
47
  self.crypt_keeper_encryptor = crypt_keeper_options.delete(:encryptor)
98
48
  self.crypt_keeper_fields = args
99
49
 
100
50
  ensure_valid_encryptor!
101
- define_crypt_keeper_callbacks
102
- end
103
51
 
104
- # Public: Encrypts a string with the encryptor
105
- def encrypt(value)
106
- encryptor.encrypt value
107
- end
52
+ before_save :enforce_column_types_callback
108
53
 
109
- # Public: Decrypts a string with the encryptor
110
- def decrypt(value)
111
- encryptor.decrypt value
54
+ crypt_keeper_fields.each do |field|
55
+ serialize field, encryptor_klass.new(crypt_keeper_options)
56
+ end
112
57
  end
113
58
 
114
59
  private
115
60
 
116
- # Private: An instance of the encryptor class
117
- def encryptor
118
- @encryptor ||= if crypt_keeper_encryptor.blank?
119
- raise ArgumentError.new('You must specify an encryptor')
120
- else
121
- encryptor_klass.new(crypt_keeper_options.dup)
122
- end
123
- end
124
-
125
61
  # Private: The encryptor class
126
62
  def encryptor_klass
127
63
  @encryptor_klass ||= "CryptKeeper::Provider::#{crypt_keeper_encryptor.to_s.camelize}".constantize
@@ -129,17 +65,15 @@ module CryptKeeper
129
65
 
130
66
  # Private: Ensure that the encryptor responds to new
131
67
  def ensure_valid_encryptor!
132
- unless defined? encryptor_klass
68
+ unless defined?(encryptor_klass) && valid_encryptor?
133
69
  raise "You must specify a valid encryptor `crypt_keeper :encryptor => :aes`"
134
70
  end
135
71
  end
136
72
 
137
- # Private: Define callbacks for encryption
138
- def define_crypt_keeper_callbacks
139
- after_save :decrypt_callback
140
- after_find :decrypt_callback
141
- before_save :encrypt_callback
142
- before_save :enforce_column_types_callback
73
+ # Private: Checks if the encryptor response to dump and load
74
+ def valid_encryptor?
75
+ encryptor_klass.instance_methods.include?(:dump) &&
76
+ encryptor_klass.instance_methods.include?(:load)
143
77
  end
144
78
  end
145
79
  end
@@ -5,6 +5,9 @@ require 'base64'
5
5
  module CryptKeeper
6
6
  module Provider
7
7
  class Aes
8
+ include CryptKeeper::Helper::Serializer
9
+
10
+ # A value to split the iv and cipher text with
8
11
  SEPARATOR = ":crypt_keeper:"
9
12
 
10
13
  # Public: The encryption key
@@ -54,4 +57,4 @@ module CryptKeeper
54
57
  end
55
58
  end
56
59
  end
57
- end
60
+ end
@@ -4,6 +4,7 @@ module CryptKeeper
4
4
  module Provider
5
5
  class MysqlAes
6
6
  include CryptKeeper::Helper::SQL
7
+ include CryptKeeper::Helper::Serializer
7
8
 
8
9
  attr_accessor :key
9
10
 
@@ -4,6 +4,8 @@ module CryptKeeper
4
4
  module Provider
5
5
  class PostgresPgp
6
6
  include CryptKeeper::Helper::SQL
7
+ include CryptKeeper::Helper::Serializer
8
+
7
9
  attr_accessor :key
8
10
  attr_accessor :pgcrypto_options
9
11
 
@@ -1,3 +1,3 @@
1
1
  module CryptKeeper
2
- VERSION = "0.13.1"
2
+ VERSION = "0.14.0.pre"
3
3
  end
data/spec/model_spec.rb CHANGED
@@ -32,114 +32,41 @@ module CryptKeeper
32
32
  end
33
33
 
34
34
  context "Options" do
35
- it "stores options in crypt_keeper_options" do
36
- subject.crypt_keeper :storage, :secret, key1: 1, key2: 2, encryptor: :fake_encryptor
37
- subject.crypt_keeper_options.should == { key1: 1, key2: 2 }
38
- end
39
-
40
35
  it "accepts the class name as a string" do
41
36
  subject.crypt_keeper :storage, :secret, key1: 1, key2: 2, encryptor: "FakeEncryptor"
42
37
  subject.send(:encryptor_klass).should == CryptKeeper::Provider::FakeEncryptor
43
38
  end
44
39
 
45
40
  it "raises an error on missing encryptor" do
46
- msg = "You must specify an encryptor"
47
- subject.crypt_keeper :storage, :secret
48
- expect { subject.create! storage: 'asdf' }.to raise_error(ArgumentError, msg)
41
+ expect { subject.crypt_keeper :storage, :secret }.
42
+ to raise_error(RuntimeError, /You must specify a valid encryptor/)
49
43
  end
50
44
  end
51
45
  end
52
46
 
53
- context "Encryption" do
47
+ context "Encryption and Decryption" do
54
48
  let(:plain_text) { 'plain_text' }
55
49
  let(:cipher_text) { 'tooltxet_nialp' }
50
+ let(:encryptor) { CryptKeeper::Provider::Encryptor }
56
51
 
57
52
  before do
58
53
  SensitiveData.crypt_keeper :storage, passphrase: 'tool', encryptor: :encryptor
59
54
  end
60
55
 
61
- subject { SensitiveData.new }
62
-
63
- describe "#encrypt" do
64
- it "should encrypt the data" do
65
- subject.storage = plain_text
66
- subject.stub :decrypt_callback
67
- subject.save!
68
- subject.storage.should == cipher_text
69
- end
70
-
71
- it "should not encrypt nil" do
72
- subject.storage = nil
73
- subject.stub :decrypt_callback
74
- subject.save!
75
- subject.storage.should be_nil
76
- end
77
- end
78
-
79
- describe "#decrypt" do
80
- it "should decrypt the data" do
81
- subject.storage = cipher_text
82
- subject.stub :encrypt_callback
83
- subject.save!
84
- subject.storage.should == plain_text
85
- end
86
-
87
- it "should not decrypt nil" do
88
- subject.storage = nil
89
- subject.stub :encrypt_callback
90
- subject.save!
91
- subject.storage.should be_nil
92
- end
56
+ it "encrypts the data" do
57
+ CryptKeeper::Provider::Encryptor.any_instance.should_receive(:dump).with('testing')
58
+ SensitiveData.create!(storage: 'testing')
93
59
  end
94
60
 
95
- describe "Encrypt & Decrypt" do
96
- it "should encrypt and decrypt the data" do
97
- subject.storage = plain_text
98
- subject.save!
99
- subject.storage.should == plain_text
100
- end
61
+ it "decrypts the data" do
62
+ record = SensitiveData.create!(storage: 'testing')
63
+ CryptKeeper::Provider::Encryptor.any_instance.should_receive(:load).at_least(1).times.with('toolgnitset')
64
+ SensitiveData.find(record).storage
101
65
  end
102
66
 
103
- describe "#encryptor" do
104
- let(:encryptor) do
105
- Class.new do
106
- def initialize(options = {})
107
- options.delete :passphrase
108
- end
109
- end
110
- end
111
-
112
- before do
113
- SensitiveData.crypt_keeper :storage, passphrase: 'tool', encryptor: encryptor
114
- end
115
-
116
- it "should dup the options" do
117
- SensitiveData.send :encryptor
118
- SensitiveData.crypt_keeper_options.should include(passphrase: 'tool')
119
- end
120
- end
121
-
122
- describe "Dirty records" do
123
- before do
124
- SensitiveData.crypt_keeper :storage, passphrase: 'tool', encryptor: :postgres_pgp
125
- end
126
-
127
- let(:record) do
128
- SensitiveData.create storage: 'test'
129
- end
130
-
131
- specify { record.should_not be_changed }
132
-
133
- it "unchanged plaintext does not trigger a save" do
134
- queries = logged_queries do
135
- SensitiveData.find(record.id).save
136
- end
137
-
138
- updates = queries.select { |query| query.match(/^UPDATE /) }
139
-
140
- queries.should_not be_empty
141
- updates.should be_empty, "Received #{updates}"
142
- end
67
+ it "returns the plaintext on decrypt" do
68
+ record = SensitiveData.create!(storage: 'testing')
69
+ SensitiveData.find(record).storage.should == 'testing'
143
70
  end
144
71
  end
145
72
  end
@@ -64,4 +64,4 @@ module CryptKeeper
64
64
  end
65
65
  end
66
66
  end
67
- end
67
+ end
@@ -2,8 +2,18 @@
2
2
  module CryptKeeper
3
3
  module Provider
4
4
  class FakeEncryptor
5
+ include CryptKeeper::Helper::Serializer
6
+
5
7
  def initialize(*args)
6
8
  end
9
+
10
+ def encrypt(value)
11
+ value
12
+ end
13
+
14
+ def decrypt(value)
15
+ value
16
+ end
7
17
  end
8
18
  end
9
19
  end
@@ -13,6 +23,8 @@ end
13
23
  module CryptKeeper
14
24
  module Provider
15
25
  class Encryptor
26
+ include CryptKeeper::Helper::Serializer
27
+
16
28
  def initialize(options = {})
17
29
  @passphrase = options[:passphrase]
18
30
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crypt_keeper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.1
5
- prerelease:
4
+ version: 0.14.0.pre
5
+ prerelease: 7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Justin Mazzi
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-26 00:00:00.000000000 Z
12
+ date: 2013-08-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -19,6 +19,9 @@ dependencies:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '3.0'
22
+ - - <
23
+ - !ruby/object:Gem::Version
24
+ version: '4.1'
22
25
  type: :runtime
23
26
  prerelease: false
24
27
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,6 +30,9 @@ dependencies:
27
30
  - - ! '>='
28
31
  - !ruby/object:Gem::Version
29
32
  version: '3.0'
33
+ - - <
34
+ - !ruby/object:Gem::Version
35
+ version: '4.1'
30
36
  - !ruby/object:Gem::Dependency
31
37
  name: activesupport
32
38
  requirement: !ruby/object:Gem::Requirement
@@ -35,6 +41,9 @@ dependencies:
35
41
  - - ! '>='
36
42
  - !ruby/object:Gem::Version
37
43
  version: '3.0'
44
+ - - <
45
+ - !ruby/object:Gem::Version
46
+ version: '4.1'
38
47
  type: :runtime
39
48
  prerelease: false
40
49
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,6 +52,9 @@ dependencies:
43
52
  - - ! '>='
44
53
  - !ruby/object:Gem::Version
45
54
  version: '3.0'
55
+ - - <
56
+ - !ruby/object:Gem::Version
57
+ version: '4.1'
46
58
  - !ruby/object:Gem::Dependency
47
59
  name: rspec
48
60
  requirement: !ruby/object:Gem::Requirement
@@ -248,7 +260,8 @@ files:
248
260
  - spec/support/active_record.rb
249
261
  - spec/support/encryptors.rb
250
262
  homepage: http://jmazzi.github.com/crypt_keeper/
251
- licenses: []
263
+ licenses:
264
+ - MIT
252
265
  post_install_message:
253
266
  rdoc_options: []
254
267
  require_paths:
@@ -261,16 +274,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
261
274
  version: '0'
262
275
  segments:
263
276
  - 0
264
- hash: -3516643146685656849
277
+ hash: 1952182874889799881
265
278
  required_rubygems_version: !ruby/object:Gem::Requirement
266
279
  none: false
267
280
  requirements:
268
- - - ! '>='
281
+ - - ! '>'
269
282
  - !ruby/object:Gem::Version
270
- version: '0'
271
- segments:
272
- - 0
273
- hash: -3516643146685656849
283
+ version: 1.3.1
274
284
  requirements: []
275
285
  rubyforge_project:
276
286
  rubygems_version: 1.8.23