attr_cipher 1.4.0 → 1.5.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/MIT-LICENSE +1 -1
- data/README.md +6 -6
- data/lib/attr_cipher/attr_cipher.rb +2 -11
- data/lib/attr_cipher/cipher.rb +20 -23
- data/lib/attr_cipher/secret_exception.rb +4 -0
- data/lib/attr_cipher/version.rb +1 -1
- data/lib/attr_cipher.rb +1 -0
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed7ac40e52f0199687e0ab1c37631bc1c9e467cb
|
4
|
+
data.tar.gz: 22672d14a563134ae6f19ad3b1e57e3afc8180a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5a86beddafd05bb1ecf5b35820f798b8609f32e06fbb97741f74acf7d5a6b00a97459604ecf45cf62e7abd7185552a6a622119343b661fd2e39bcac050f921f
|
7
|
+
data.tar.gz: 68cdbc62e3b4cb5e4871a715444740a31143129c35e9474a2d9de11c65ab85ac10efc0198f8d3925f2877e047b7b3f3b45d202f046ca5d0f24e66f1050c444ea
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
##v1.5.0
|
4
|
+
- Created `AttrCipher::SecretException` class.
|
5
|
+
- Updated FactoryGirl to FactoryBot (dev dependency).
|
6
|
+
- Updated Codecov to ~> 0.16.1 (dev dependency).
|
7
|
+
- Added Ruby 2.4.4 to Travis CI config.
|
8
|
+
- Switched serialize option to use Marshal instead of YAML.
|
9
|
+
- Refactored cipher.
|
10
|
+
|
3
11
|
##v1.4.0
|
4
|
-
- Added serialize option to attr_cipher class method. Can now seamlessly handle value types other than just strings.
|
12
|
+
- Added serialize option to `attr_cipher` class method. Can now seamlessly handle value types other than just strings.
|
5
13
|
|
6
14
|
##v1.3.1
|
7
15
|
- Fixed failing spec.
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -29,18 +29,18 @@ Development/Test:
|
|
29
29
|
- rake (~> 10.5)
|
30
30
|
- rspec (~> 3.4)
|
31
31
|
- sqlite3 (~> 1.3)
|
32
|
-
- simplecov (~> 0.
|
33
|
-
-
|
32
|
+
- simplecov (~> 0.16.1)
|
33
|
+
- factory_bot (~> 4.8.2)
|
34
34
|
|
35
35
|
## Compatibility
|
36
36
|
|
37
|
-
Tested with Ruby 2.
|
37
|
+
Tested with Ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin16] against ActiveRecord 5.1.4 on macOS Sierra 10.13.4 (17E202).
|
38
38
|
|
39
39
|
**AttrCipher** uses OpenSSL to perform the cipher.
|
40
40
|
|
41
41
|
## Usage
|
42
42
|
|
43
|
-
**AttrCipher** uses a global secret by default and it must be at least 100 characters or more. You can set the secret by setting `AttrCipher.secret
|
43
|
+
**AttrCipher** uses a global secret by default and it must be at least 100 characters or more. You can set the secret by setting `AttrCipher.secret` (e.g. `$ openssl rand -hex 50`).
|
44
44
|
|
45
45
|
```ruby
|
46
46
|
AttrCipher.secret = ENV['SECRET_KEY']
|
@@ -107,7 +107,7 @@ Using the serialize option will cause the value to be serialized and deserialize
|
|
107
107
|
|
108
108
|
## Tests
|
109
109
|
|
110
|
-
Tests are written using Rspec,
|
110
|
+
Tests are written using Rspec, FactoryBot and Sqlite3. There are 17 examples with 100% code coverage.
|
111
111
|
|
112
112
|
To run the tests, execute the default rake task:
|
113
113
|
|
@@ -135,4 +135,4 @@ The gem is available as open source under the terms of the [MIT License](http://
|
|
135
135
|
|
136
136
|
## Copyright
|
137
137
|
|
138
|
-
Copyright 2017 Brightcommerce, Inc.
|
138
|
+
Copyright 2017-2018 Brightcommerce, Inc.
|
@@ -1,16 +1,9 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
require 'active_support/all'
|
3
|
-
require 'yaml'
|
4
3
|
|
5
4
|
module AttrCipher
|
6
5
|
extend ActiveSupport::Concern
|
7
6
|
|
8
|
-
class Error < ::StandardError
|
9
|
-
end
|
10
|
-
|
11
|
-
class SecretTooShortException < Error
|
12
|
-
end
|
13
|
-
|
14
7
|
class << self
|
15
8
|
attr_accessor :cipher
|
16
9
|
attr_reader :secret
|
@@ -36,16 +29,14 @@ module AttrCipher
|
|
36
29
|
define_method attribute do
|
37
30
|
value = instance_variable_get("@#{attribute}")
|
38
31
|
cipher_value = send("#{attribute}_cipher") unless value
|
39
|
-
value = cipher.decrypt(secret, cipher_value) if cipher_value
|
40
|
-
value = YAML::load(value) if serialize
|
32
|
+
value = cipher.decrypt(secret, cipher_value, serialize) if cipher_value
|
41
33
|
instance_variable_set("@#{attribute}", value)
|
42
34
|
end
|
43
35
|
|
44
36
|
define_method "#{attribute}=" do |value|
|
45
37
|
instance_variable_set("@#{attribute}", value)
|
46
|
-
value = YAML::dump(value) if serialize
|
47
38
|
send("#{attribute}_cipher=", nil)
|
48
|
-
send("#{attribute}_cipher=", cipher.encrypt(secret, value)) if value && value != ""
|
39
|
+
send("#{attribute}_cipher=", cipher.encrypt(secret, value, serialize)) if value && value != ""
|
49
40
|
end
|
50
41
|
end
|
51
42
|
end
|
data/lib/attr_cipher/cipher.rb
CHANGED
@@ -6,10 +6,9 @@ module AttrCipher
|
|
6
6
|
class Cipher
|
7
7
|
ALGORITHM = "AES-256-CBC".freeze
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
def initialize(secret)
|
9
|
+
def initialize(secret = nil, serialize = false)
|
12
10
|
@secret = secret
|
11
|
+
@serialize = serialize
|
13
12
|
end
|
14
13
|
|
15
14
|
def cipher(mode, value)
|
@@ -20,34 +19,32 @@ module AttrCipher
|
|
20
19
|
cipher.update(value) + cipher.final
|
21
20
|
end
|
22
21
|
|
23
|
-
def decode(value)
|
24
|
-
Base64.decode64(value)
|
25
|
-
end
|
26
|
-
|
27
22
|
def decrypt(value)
|
28
|
-
|
29
|
-
"Secret must have at least 100 characters"
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
Base64.encode64(value).chomp
|
23
|
+
if @secret.nil? || (@secret.respond_to?(:size) && @secret.size < 100)
|
24
|
+
raise SecretException.new("Secret not set or must have at least 100 characters.")
|
25
|
+
else
|
26
|
+
decoded = Base64.decode64(value)
|
27
|
+
decrypted = cipher(:decrypt, decoded)
|
28
|
+
@serialize ? Marshal.load(decrypted) : decrypted
|
29
|
+
end
|
36
30
|
end
|
37
31
|
|
38
32
|
def encrypt(value)
|
39
|
-
|
40
|
-
"Secret must have at least 100 characters"
|
41
|
-
|
42
|
-
|
33
|
+
if @secret.nil? || (@secret.respond_to?(:size) && @secret.size < 100)
|
34
|
+
raise SecretException.new("Secret not set or must have at least 100 characters.")
|
35
|
+
else
|
36
|
+
data = @serialize ? Marshal.dump(value) : value.to_s
|
37
|
+
encrypted = cipher(:encrypt, data)
|
38
|
+
Base64.encode64(encrypted).chomp
|
39
|
+
end
|
43
40
|
end
|
44
41
|
|
45
|
-
def self.decrypt(secret, value)
|
46
|
-
new(secret).decrypt(value)
|
42
|
+
def self.decrypt(secret, value, serialize = false)
|
43
|
+
new(secret, serialize).decrypt(value)
|
47
44
|
end
|
48
45
|
|
49
|
-
def self.encrypt(secret, value)
|
50
|
-
new(secret).encrypt(value)
|
46
|
+
def self.encrypt(secret, value, serialize = false)
|
47
|
+
new(secret, serialize).encrypt(value)
|
51
48
|
end
|
52
49
|
end
|
53
50
|
end
|
data/lib/attr_cipher/version.rb
CHANGED
data/lib/attr_cipher.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.5.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:
|
11
|
+
date: 2018-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -81,33 +81,33 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.3'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: factory_bot
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 4.8.2
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 4.8.2
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: simplecov
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.
|
103
|
+
version: 0.16.1
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.
|
110
|
+
version: 0.16.1
|
111
111
|
description: Provides functionality to transparently store and retrieve encrypted
|
112
112
|
attributes in ActiveRecord models.
|
113
113
|
email:
|
@@ -122,12 +122,13 @@ files:
|
|
122
122
|
- lib/attr_cipher.rb
|
123
123
|
- lib/attr_cipher/attr_cipher.rb
|
124
124
|
- lib/attr_cipher/cipher.rb
|
125
|
+
- lib/attr_cipher/secret_exception.rb
|
125
126
|
- lib/attr_cipher/version.rb
|
126
127
|
homepage: https://github.com/brightcommerce/attr_cipher
|
127
128
|
licenses:
|
128
129
|
- MIT
|
129
130
|
metadata:
|
130
|
-
copyright: Copyright 2017 Brightcommerce, Inc.
|
131
|
+
copyright: Copyright 2017-2018 Brightcommerce, Inc.
|
131
132
|
post_install_message:
|
132
133
|
rdoc_options: []
|
133
134
|
require_paths:
|
@@ -144,8 +145,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
145
|
version: '0'
|
145
146
|
requirements: []
|
146
147
|
rubyforge_project:
|
147
|
-
rubygems_version: 2.
|
148
|
+
rubygems_version: 2.6.13
|
148
149
|
signing_key:
|
149
150
|
specification_version: 4
|
150
|
-
summary: AttrCipher v1.
|
151
|
+
summary: AttrCipher v1.5.0
|
151
152
|
test_files: []
|