encrypt_attr 0.1.0 → 0.2.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 +4 -0
- data/README.md +13 -3
- data/Rakefile +4 -4
- data/encrypt_attr.gemspec +2 -2
- data/lib/encrypt_attr/base.rb +8 -5
- data/lib/encrypt_attr/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64d1f65f2d3aaf72b3bf4e0fc66b43a2702f80d4
|
4
|
+
data.tar.gz: 6ee5571af9bf005cf5da3d9d780881dc965194e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b950542fee37e987304b88e58985bb00d26d4825fe223a5fe78926b59122f08ca6e4a16943b564badef324a9a2ae0c353a549a4d5e8bdb7785a95b3ae4af00b
|
7
|
+
data.tar.gz: 128849e268fd76b0cf6e4a43f02614851fb0084985abd67432a4a9e1bdccc8a4482770c8e1d250a39c4894c3a253245bde6fadc956690d31068ad11933ad424b
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
[![Code Climate](https://codeclimate.com/github/fnando/encrypt_attr/badges/gpa.svg)](https://codeclimate.com/github/fnando/encrypt_attr)
|
5
5
|
[![Test Coverage](https://codeclimate.com/github/fnando/encrypt_attr/badges/coverage.svg)](https://codeclimate.com/github/fnando/encrypt_attr)
|
6
6
|
|
7
|
-
Encrypt attributes using AES-256-CBC (or your custom encryption
|
7
|
+
Encrypt attributes using AES-256-CBC (or your custom encryption strategy). Works with and without ActiveRecord.
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -44,7 +44,7 @@ The `encrypt_attr` method has some aliases, so you can also use any of these:
|
|
44
44
|
- `encrypted_attr`
|
45
45
|
- `encrypted_attribute`
|
46
46
|
|
47
|
-
This assumes that you have a `encrypted_api_key` attribute. By default, the value is encrypted using a global secret token. You can set a custom token by setting `EncryptAttr.secret_token`; you have
|
47
|
+
This assumes that you have a `encrypted_api_key` attribute. By default, the value is encrypted using a global secret token. You can set a custom token by setting `EncryptAttr.secret_token`; you have to use 100 characters or more (e.g. `$ openssl rand -hex 50`).
|
48
48
|
|
49
49
|
```ruby
|
50
50
|
EncryptAttr.secret_token = 'abc123'
|
@@ -56,7 +56,7 @@ You can also set the secret token per attribute basis.
|
|
56
56
|
class User
|
57
57
|
include EncryptAttr
|
58
58
|
attr_accessor :encrypted_api_key
|
59
|
-
encrypt_attr :api_key,
|
59
|
+
encrypt_attr :api_key, secret_token: USER_SECRET_TOKEN
|
60
60
|
end
|
61
61
|
```
|
62
62
|
|
@@ -131,6 +131,16 @@ user.api_key = 'API_KEY'
|
|
131
131
|
user.encrypted_api_key #=> 'YEK_IPA'
|
132
132
|
```
|
133
133
|
|
134
|
+
You can also specify a custom encryptor per attribute.
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
class User
|
138
|
+
include EncryptAttr
|
139
|
+
attr_accessor :encrypted_api_key
|
140
|
+
attr_encrypted :api_key, encryptor: ReverseEncryptor
|
141
|
+
end
|
142
|
+
```
|
143
|
+
|
134
144
|
## Development
|
135
145
|
|
136
146
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Rakefile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
require 'rake/testtask'
|
3
3
|
|
4
|
-
Rake::TestTask.new(:
|
5
|
-
t.libs << '
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.libs << 'test'
|
6
6
|
t.libs << 'lib'
|
7
|
-
t.test_files = FileList['
|
7
|
+
t.test_files = FileList['test/**/*_test.rb']
|
8
8
|
end
|
9
9
|
|
10
|
-
task :default => :
|
10
|
+
task :default => :test
|
11
11
|
|
data/encrypt_attr.gemspec
CHANGED
@@ -5,7 +5,7 @@ Gem::Specification.new do |spec|
|
|
5
5
|
spec.version = EncryptAttr::VERSION
|
6
6
|
spec.authors = ['Nando Vieira']
|
7
7
|
spec.email = ['fnando.vieira@gmail.com']
|
8
|
-
spec.summary = 'Encrypt attributes using AES-256-CBC (or your custom encryption
|
8
|
+
spec.summary = 'Encrypt attributes using AES-256-CBC (or your custom encryption strategy). Works with and without ActiveRecord.'
|
9
9
|
spec.description = spec.summary
|
10
10
|
spec.homepage = 'http://rubygems.org/gems/encrypt_attr'
|
11
11
|
spec.license = 'MIT'
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.add_development_dependency 'bundler'
|
19
19
|
spec.add_development_dependency 'rake'
|
20
20
|
spec.add_development_dependency 'minitest'
|
21
|
-
spec.add_development_dependency 'minitest-
|
21
|
+
spec.add_development_dependency 'minitest-utils'
|
22
22
|
spec.add_development_dependency 'sqlite3'
|
23
23
|
spec.add_development_dependency 'activerecord'
|
24
24
|
spec.add_development_dependency 'pry-meta'
|
data/lib/encrypt_attr/base.rb
CHANGED
@@ -36,11 +36,11 @@ module EncryptAttr
|
|
36
36
|
self.encryptor = Encryptor
|
37
37
|
|
38
38
|
module ClassMethods
|
39
|
-
def encrypt_attr(*args, secret_token: EncryptAttr.secret_token)
|
39
|
+
def encrypt_attr(*args, secret_token: EncryptAttr.secret_token, encryptor: EncryptAttr.encryptor)
|
40
40
|
EncryptAttr.validate_secret_token(secret_token)
|
41
41
|
|
42
42
|
args.each do |attribute|
|
43
|
-
define_encrypted_attribute(attribute, secret_token)
|
43
|
+
define_encrypted_attribute(attribute, secret_token, encryptor)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
alias_method :attr_encrypt, :encrypt_attr
|
@@ -53,15 +53,18 @@ module EncryptAttr
|
|
53
53
|
|
54
54
|
private
|
55
55
|
|
56
|
-
def define_encrypted_attribute(attribute, secret_token)
|
56
|
+
def define_encrypted_attribute(attribute, secret_token, encryptor)
|
57
57
|
define_method attribute do
|
58
|
-
instance_variable_get("@#{attribute}")
|
58
|
+
value = instance_variable_get("@#{attribute}")
|
59
|
+
encrypted_value = send("encrypted_#{attribute}") unless value
|
60
|
+
value = encryptor.decrypt(secret_token, encrypted_value) if encrypted_value
|
61
|
+
instance_variable_set("@#{attribute}", value)
|
59
62
|
end
|
60
63
|
|
61
64
|
define_method "#{attribute}=" do |value|
|
62
65
|
instance_variable_set("@#{attribute}", value)
|
63
66
|
send("encrypted_#{attribute}=", nil)
|
64
|
-
send("encrypted_#{attribute}=",
|
67
|
+
send("encrypted_#{attribute}=", encryptor.encrypt(secret_token, value)) if value
|
65
68
|
end
|
66
69
|
end
|
67
70
|
end
|
data/lib/encrypt_attr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: encrypt_attr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: minitest-
|
56
|
+
name: minitest-utils
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -122,7 +122,7 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
-
description: Encrypt attributes using AES-256-CBC (or your custom encryption
|
125
|
+
description: Encrypt attributes using AES-256-CBC (or your custom encryption strategy).
|
126
126
|
Works with and without ActiveRecord.
|
127
127
|
email:
|
128
128
|
- fnando.vieira@gmail.com
|
@@ -164,9 +164,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
164
|
version: '0'
|
165
165
|
requirements: []
|
166
166
|
rubyforge_project:
|
167
|
-
rubygems_version: 2.4.
|
167
|
+
rubygems_version: 2.4.5.1
|
168
168
|
signing_key:
|
169
169
|
specification_version: 4
|
170
|
-
summary: Encrypt attributes using AES-256-CBC (or your custom encryption
|
170
|
+
summary: Encrypt attributes using AES-256-CBC (or your custom encryption strategy).
|
171
171
|
Works with and without ActiveRecord.
|
172
172
|
test_files: []
|