attr_encryption 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: acd5e4eab70392658a813fc269594f9172725646
4
- data.tar.gz: b517d95ae98b5cd7537ff0cf40ed52275c632b85
3
+ metadata.gz: 33fa4e0a2ea08d7944beeaccc72375d423323211
4
+ data.tar.gz: 604463429d71957f5a018bdb978a255016114fb7
5
5
  SHA512:
6
- metadata.gz: caf52c3ef1935397886f25c58290c78a3344632c8373bd223a9cbd5d1398a87ed1be5351fbd4fb33142f892ff7c86761a50fc57b935e9f1c61a0026ee0a2373c
7
- data.tar.gz: 87e5a93df2785e93b0d83af5bee82808cff9753f755ff8e27fbb3fe3083751070752c9adafa5f6f8d7a1f27d0a4220493244378cb797440e026aa811b966c36b
6
+ metadata.gz: b045b50352b1d37810708c50406a1b64a50cf74f9a58f4b33c7950346d0c0b16e2abf33d60f177e123a7a9c74dd96d3c262b25f91c9e5708a785d4e4206729bc
7
+ data.tar.gz: 84f8ed41f05e49acb68d00601f60adc1af6b0c2de46d6d6b3c558312c0e56b48eec7a4c6ee6965c13b6f327dfe36c626af84c47a568e142a65509bb3a621642a
data/Gemfile CHANGED
@@ -7,7 +7,7 @@ gem "activesupport", ">= 3.2.14"
7
7
  # Include everything needed to run rake, tests, features, etc.
8
8
  group :development do
9
9
  gem "rspec"
10
- gem "rdoc", "~> 3.12"
10
+ gem "rdoc", "~> 4.1"
11
11
  gem "bundler", "~> 1.0"
12
12
  gem "jeweler", "~> 1.8.7"
13
13
  end
data/Gemfile.lock CHANGED
@@ -1,15 +1,18 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activesupport (3.2.14)
5
- i18n (~> 0.6, >= 0.6.4)
6
- multi_json (~> 1.0)
7
- addressable (2.3.5)
4
+ activesupport (4.1.4)
5
+ i18n (~> 0.6, >= 0.6.9)
6
+ json (~> 1.7, >= 1.7.7)
7
+ minitest (~> 5.1)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 1.1)
10
+ addressable (2.3.6)
8
11
  builder (3.2.2)
9
- diff-lcs (1.2.4)
10
- faraday (0.8.8)
12
+ diff-lcs (1.2.5)
13
+ faraday (0.8.9)
11
14
  multipart-post (~> 1.2.0)
12
- git (1.2.6)
15
+ git (1.2.8)
13
16
  github_api (0.10.1)
14
17
  addressable
15
18
  faraday (~> 0.8.1)
@@ -17,11 +20,10 @@ GEM
17
20
  multi_json (~> 1.4)
18
21
  nokogiri (~> 1.5.2)
19
22
  oauth2
20
- hashie (2.0.5)
21
- highline (1.6.19)
22
- httpauth (0.2.0)
23
- i18n (0.6.5)
24
- jeweler (1.8.7)
23
+ hashie (3.2.0)
24
+ highline (1.6.21)
25
+ i18n (0.6.11)
26
+ jeweler (1.8.8)
25
27
  builder
26
28
  bundler (~> 1.0)
27
29
  git (>= 1.2.5)
@@ -30,32 +32,38 @@ GEM
30
32
  nokogiri (= 1.5.10)
31
33
  rake
32
34
  rdoc
33
- json (1.8.0)
34
- jwt (0.1.8)
35
- multi_json (>= 1.5)
36
- multi_json (1.8.0)
35
+ json (1.8.1)
36
+ jwt (1.0.0)
37
+ minitest (5.4.0)
38
+ multi_json (1.10.1)
37
39
  multi_xml (0.5.5)
38
40
  multipart-post (1.2.0)
39
41
  nokogiri (1.5.10)
40
- oauth2 (0.9.2)
41
- faraday (~> 0.8)
42
- httpauth (~> 0.2)
43
- jwt (~> 0.1.4)
44
- multi_json (~> 1.0)
42
+ oauth2 (1.0.0)
43
+ faraday (>= 0.8, < 0.10)
44
+ jwt (~> 1.0)
45
+ multi_json (~> 1.3)
45
46
  multi_xml (~> 0.5)
46
47
  rack (~> 1.2)
47
48
  rack (1.5.2)
48
- rake (10.1.0)
49
- rdoc (3.12.2)
49
+ rake (10.3.2)
50
+ rdoc (4.1.1)
50
51
  json (~> 1.4)
51
- rspec (2.14.1)
52
- rspec-core (~> 2.14.0)
53
- rspec-expectations (~> 2.14.0)
54
- rspec-mocks (~> 2.14.0)
55
- rspec-core (2.14.5)
56
- rspec-expectations (2.14.3)
57
- diff-lcs (>= 1.1.3, < 2.0)
58
- rspec-mocks (2.14.3)
52
+ rspec (3.0.0)
53
+ rspec-core (~> 3.0.0)
54
+ rspec-expectations (~> 3.0.0)
55
+ rspec-mocks (~> 3.0.0)
56
+ rspec-core (3.0.4)
57
+ rspec-support (~> 3.0.0)
58
+ rspec-expectations (3.0.4)
59
+ diff-lcs (>= 1.2.0, < 2.0)
60
+ rspec-support (~> 3.0.0)
61
+ rspec-mocks (3.0.4)
62
+ rspec-support (~> 3.0.0)
63
+ rspec-support (3.0.4)
64
+ thread_safe (0.3.4)
65
+ tzinfo (1.2.2)
66
+ thread_safe (~> 0.1)
59
67
 
60
68
  PLATFORMS
61
69
  ruby
@@ -64,5 +72,5 @@ DEPENDENCIES
64
72
  activesupport (>= 3.2.14)
65
73
  bundler (~> 1.0)
66
74
  jeweler (~> 1.8.7)
67
- rdoc (~> 3.12)
75
+ rdoc (~> 4.1)
68
76
  rspec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -0,0 +1,69 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: attr_encryption 0.1.2 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "attr_encryption"
9
+ s.version = "0.1.2"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["Dave Sieh"]
14
+ s.date = "2014-08-15"
15
+ s.description = "Provides an extension for Ruby and rails object to support a flexible means of encrypting attributes."
16
+ s.email = "dave.sieh@providigm.com"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".rspec",
24
+ "Gemfile",
25
+ "Gemfile.lock",
26
+ "LICENSE.txt",
27
+ "README.rdoc",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "attr_encryption.gemspec",
31
+ "lib/attr_encryption.rb",
32
+ "lib/attr_encryption/adapters/active_record.rb",
33
+ "lib/attr_encryption/date_extensions.rb",
34
+ "lib/attr_encryption/mysql_encryption.rb",
35
+ "lib/attr_encryption/mysql_encryptor.rb",
36
+ "spec/mysql_encryption_spec.rb",
37
+ "spec/mysql_encryptor_spec.rb",
38
+ "spec/spec_helper.rb"
39
+ ]
40
+ s.homepage = "http://github.com/GitHubAdmin/attr_encryption"
41
+ s.licenses = ["MIT"]
42
+ s.rubygems_version = "2.2.2"
43
+ s.summary = "Extends Object and ActiveRecord::Base objects to support encrypted attributes"
44
+
45
+ if s.respond_to? :specification_version then
46
+ s.specification_version = 4
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_runtime_dependency(%q<activesupport>, [">= 3.2.14"])
50
+ s.add_development_dependency(%q<rspec>, [">= 0"])
51
+ s.add_development_dependency(%q<rdoc>, ["~> 4.1"])
52
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
53
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.7"])
54
+ else
55
+ s.add_dependency(%q<activesupport>, [">= 3.2.14"])
56
+ s.add_dependency(%q<rspec>, [">= 0"])
57
+ s.add_dependency(%q<rdoc>, ["~> 4.1"])
58
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
59
+ s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<activesupport>, [">= 3.2.14"])
63
+ s.add_dependency(%q<rspec>, [">= 0"])
64
+ s.add_dependency(%q<rdoc>, ["~> 4.1"])
65
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
66
+ s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
67
+ end
68
+ end
69
+
@@ -24,7 +24,7 @@ module AttrEncryption
24
24
  # one attribute to encrypt at a time or when the :prefix and :suffix options
25
25
  # aren't enough. Defaults to nil.
26
26
  #
27
- # :type => The data type of the value to be encrypted/decrypted. Can be 'date', 'datetime', 'binary' or 'text'.
27
+ # :type => The data type of the value to be encrypted/decrypted. Can be 'date', 'datetime', 'binary', 'text' or json.
28
28
  # When encrypting, all values will use their string value (value.to_s). When decrypting,
29
29
  # the type of the value will determine what is returned. For example:
30
30
  #
@@ -32,6 +32,7 @@ module AttrEncryption
32
32
  # type = 'time': DateTime.parse(decrypted_value)
33
33
  # type = 'binary': decrypted_value
34
34
  # type = 'text': decrypted_value.force_encoding('utf-8')
35
+ # type = 'json': JSON.parse(decrypted_value)
35
36
  #
36
37
  # :prefix => A prefix used to generate the name of the referenced encrypted attributes.
37
38
  # For example <tt>attr_accessor :email, :password, :prefix => 'crypted_'</tt> would
@@ -143,13 +144,25 @@ module AttrEncryption
143
144
 
144
145
  define_method(attribute) do
145
146
  cached_value = instance_variable_get("@#{attribute}")
146
- value = cached_value && options[:type] == 'date' && cached_value.is_a?(Date) ? cached_value : nil
147
+ if cached_value
148
+ case options[:type]
149
+ when 'date'
150
+ value = cached_value.is_a?(Date) ? cached_value : nil
151
+ when 'json'
152
+ value = cached_value.is_a?(Hash) || cached_value.is_a?(Array) ? cached_value : nil
153
+ else
154
+ value = cached_value
155
+ end
156
+ else
157
+ value = nil
158
+ end
147
159
  value || instance_variable_set("@#{attribute}", decrypt(attribute, send(encrypted_attribute_name)))
148
- # instance_variable_get("@#{attribute}") || instance_variable_set("@#{attribute}", decrypt(attribute, send(encrypted_attribute_name)))
149
160
  end
150
161
 
151
162
  define_method("#{attribute}=") do |value|
152
- send("#{encrypted_attribute_name}=", encrypt(attribute, value))
163
+ value_to_encrypt = options[:type] == 'json' ? value.to_json : value
164
+
165
+ send("#{encrypted_attribute_name}=", encrypt(attribute, value_to_encrypt))
153
166
  instance_variable_set("@#{attribute}", value)
154
167
  end
155
168
 
@@ -20,6 +20,8 @@ class MySQLEncryptor
20
20
  DateTime.parse(decrypted_value)
21
21
  when 'binary'
22
22
  decrypted_value # no processing
23
+ when 'json'
24
+ JSON.parse(decrypted_value)
23
25
  else
24
26
  raise "Invalid type specified for post-processing decrypted value"
25
27
  end
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attr_encryption
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Sieh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-08 00:00:00.000000000 Z
11
+ date: 2014-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.2.14
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.2.14
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rdoc
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.12'
47
+ version: '4.1'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.12'
54
+ version: '4.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: jeweler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: 1.8.7
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.8.7
83
83
  description: Provides an extension for Ruby and rails object to support a flexible
@@ -89,14 +89,15 @@ extra_rdoc_files:
89
89
  - LICENSE.txt
90
90
  - README.rdoc
91
91
  files:
92
- - .document
93
- - .rspec
92
+ - ".document"
93
+ - ".rspec"
94
94
  - Gemfile
95
95
  - Gemfile.lock
96
96
  - LICENSE.txt
97
97
  - README.rdoc
98
98
  - Rakefile
99
99
  - VERSION
100
+ - attr_encryption.gemspec
100
101
  - lib/attr_encryption.rb
101
102
  - lib/attr_encryption/adapters/active_record.rb
102
103
  - lib/attr_encryption/date_extensions.rb
@@ -115,17 +116,17 @@ require_paths:
115
116
  - lib
116
117
  required_ruby_version: !ruby/object:Gem::Requirement
117
118
  requirements:
118
- - - '>='
119
+ - - ">="
119
120
  - !ruby/object:Gem::Version
120
121
  version: '0'
121
122
  required_rubygems_version: !ruby/object:Gem::Requirement
122
123
  requirements:
123
- - - '>='
124
+ - - ">="
124
125
  - !ruby/object:Gem::Version
125
126
  version: '0'
126
127
  requirements: []
127
128
  rubyforge_project:
128
- rubygems_version: 2.3.0
129
+ rubygems_version: 2.2.2
129
130
  signing_key:
130
131
  specification_version: 4
131
132
  summary: Extends Object and ActiveRecord::Base objects to support encrypted attributes