attr_cipher 1.3.1 → 1.4.0

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: c87b0d9afabd3b0a380cd69537161244a9d1bb25
4
- data.tar.gz: 4c1a4dd96803ccda04fda32cc28f88d9c14f8c9f
3
+ metadata.gz: f2170d301034202dd5c1e79cfd07ae541e9eca46
4
+ data.tar.gz: 779477637d8623cefc95241dead741ff29dd7a15
5
5
  SHA512:
6
- metadata.gz: c95d014c00f9ae57e701d7e32e2e62f3d9647f46e7e08f80175131914cf651917075680688fd2e4a00fb1a7e7e4a7d1c0603b29d167127767f27c07c5fbdfb4b
7
- data.tar.gz: 3c305b9b6f303b4b3e525e803705c5644db94c7bbd5dd564eac84ae7c99439ee5b9b1446d6b430c9c94d23fe094681337a0dbc62a4024022b225094e393cba1b
6
+ metadata.gz: 0f387a996b632e9822b611ee745cdc47a776d036a8e34951ce24566eb9e24771bc48f57be3376d30a375434942d9cb426055270d27e19a56b6bf1bbda506447f
7
+ data.tar.gz: e899394a28b337d284bf1ac6e8bcf6c718ef14bc96a542b20a1f5a3d5ab6c344592e751268db1ad94c5f2acfe1bbf5c2d9b7d5a37473946fbfd373004881fe35
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Change Log
2
2
 
3
+ ##v1.4.0
4
+ - Added serialize option to attr_cipher class method. Can now seamlessly handle value types other than just strings.
5
+
3
6
  ##v1.3.1
4
7
  - Fixed failing spec.
5
8
 
data/README.md CHANGED
@@ -34,7 +34,7 @@ Development/Test:
34
34
 
35
35
  ## Compatibility
36
36
 
37
- Tested with Ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15] against ActiveRecord 5.0.0 on macOS Sierra 10.12.4 (16E195).
37
+ Tested with Ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15] against ActiveRecord 5.1.3 on macOS Sierra 10.12.6 (16G29).
38
38
 
39
39
  **AttrCipher** uses OpenSSL to perform the cipher.
40
40
 
@@ -95,9 +95,19 @@ class User < ActiveRecord::Base
95
95
  end
96
96
  ```
97
97
 
98
+ Sometimes we need to store values that are aren't strings. In order to encrypt other value types you can pass the `serialize` option with a value of `true` to the `attr_cipher` class method:
99
+
100
+ ```ruby
101
+ class User < ActiveRecord::Base
102
+ attr_cipher :api_key, serialize: true
103
+ end
104
+ ```
105
+
106
+ Using the serialize option will cause the value to be serialized and deserialized using YAML during the encrypting and decrypting process. No changes are necessary to the column type in the table migration, it should remain as `text`.
107
+
98
108
  ## Tests
99
109
 
100
- Tests are written using Rspec, FactoryGirl and Sqlite3. There are 13 examples with 100% code coverage.
110
+ Tests are written using Rspec, FactoryGirl and Sqlite3. There are 15 examples with 100% code coverage.
101
111
 
102
112
  To run the tests, execute the default rake task:
103
113
 
@@ -1,5 +1,6 @@
1
1
  require 'active_record'
2
2
  require 'active_support/all'
3
+ require 'yaml'
3
4
 
4
5
  module AttrCipher
5
6
  extend ActiveSupport::Concern
@@ -23,24 +24,26 @@ module AttrCipher
23
24
  self.secret = ''
24
25
 
25
26
  module ClassMethods
26
- def attr_cipher(*args, secret: AttrCipher.secret, cipher: AttrCipher.cipher)
27
+ def attr_cipher(*args, secret: AttrCipher.secret, cipher: AttrCipher.cipher, serialize: false)
27
28
  args.each do |attribute|
28
- define_cipher_attribute(attribute, secret, cipher)
29
+ define_cipher_attribute(attribute, secret, cipher, serialize)
29
30
  end
30
31
  end
31
32
 
32
33
  private
33
34
 
34
- def define_cipher_attribute(attribute, secret, cipher)
35
+ def define_cipher_attribute(attribute, secret, cipher, serialize)
35
36
  define_method attribute do
36
37
  value = instance_variable_get("@#{attribute}")
37
38
  cipher_value = send("#{attribute}_cipher") unless value
38
39
  value = cipher.decrypt(secret, cipher_value) if cipher_value
40
+ value = YAML::load(value) if serialize
39
41
  instance_variable_set("@#{attribute}", value)
40
42
  end
41
43
 
42
44
  define_method "#{attribute}=" do |value|
43
45
  instance_variable_set("@#{attribute}", value)
46
+ value = YAML::dump(value) if serialize
44
47
  send("#{attribute}_cipher=", nil)
45
48
  send("#{attribute}_cipher=", cipher.encrypt(secret, value)) if value && value != ""
46
49
  end
@@ -1,8 +1,8 @@
1
1
  module AttrCipher
2
2
  module VERSION
3
3
  MAJOR = 1
4
- MINOR = 3
5
- TINY = 1
4
+ MINOR = 4
5
+ TINY = 0
6
6
  PRE = nil
7
7
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
8
8
  SUMMARY = "AttrCipher v#{STRING}"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attr_cipher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jurgen Jocubeit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-11 00:00:00.000000000 Z
11
+ date: 2017-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -147,5 +147,5 @@ rubyforge_project:
147
147
  rubygems_version: 2.5.1
148
148
  signing_key:
149
149
  specification_version: 4
150
- summary: AttrCipher v1.3.1
150
+ summary: AttrCipher v1.4.0
151
151
  test_files: []