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 +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +12 -2
- data/lib/attr_cipher/attr_cipher.rb +6 -3
- data/lib/attr_cipher/version.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2170d301034202dd5c1e79cfd07ae541e9eca46
|
4
|
+
data.tar.gz: 779477637d8623cefc95241dead741ff29dd7a15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f387a996b632e9822b611ee745cdc47a776d036a8e34951ce24566eb9e24771bc48f57be3376d30a375434942d9cb426055270d27e19a56b6bf1bbda506447f
|
7
|
+
data.tar.gz: e899394a28b337d284bf1ac6e8bcf6c718ef14bc96a542b20a1f5a3d5ab6c344592e751268db1ad94c5f2acfe1bbf5c2d9b7d5a37473946fbfd373004881fe35
|
data/CHANGELOG.md
CHANGED
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.
|
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
|
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
|
data/lib/attr_cipher/version.rb
CHANGED
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.
|
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
|
+
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.
|
150
|
+
summary: AttrCipher v1.4.0
|
151
151
|
test_files: []
|