nygma 0.1.3 → 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/README.md +30 -3
- data/Rakefile +12 -1
- data/db/migrate/20150630040253_create_encryptable_test_models.rb +8 -0
- data/lib/nygma/encryptable.rb +56 -0
- data/lib/nygma/engine.rb +4 -0
- data/lib/nygma/version.rb +1 -1
- data/lib/nygma.rb +2 -0
- metadata +51 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2bf1c9281ff6a3733b9a06256a721bd7fe55abbc
|
4
|
+
data.tar.gz: 1a9b75337c2f6edc711baf911cfbeb1c6562a0e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99ad951ab5386e8f0aa53c53f91c67bdc9961162d730f9f6129d1626c18cfe583c4b29e16a47537bdea7c64bcf08564b5534206947d510e09b1fb0b6f5a48506
|
7
|
+
data.tar.gz: 28ba8583f924066710ec0b89da00e0c7498f22a39d58dfceb223a52cbdf5922aa91fc32d6f452b8df85d3e69d24fd47eab4d54d6809f97956cbfc0fc17650be0
|
data/README.md
CHANGED
@@ -2,15 +2,42 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/bsodmike/Nygma.svg?branch=master)](https://travis-ci.org/bsodmike/Nygma)
|
4
4
|
|
5
|
-
Gotham's very own Mr. Nygma, a Rails 4 Encryptor
|
5
|
+
Gotham's very own Mr. Nygma, a Rails 4.2 attribute Encryptor
|
6
6
|
|
7
7
|
## Compatibility
|
8
8
|
|
9
|
-
*
|
10
|
-
* Travis CI for
|
9
|
+
* Requires Ruby 2
|
10
|
+
* Travis CI for 2.0.0, 2.1.0, and 2.2.2
|
11
11
|
|
12
12
|
## Usage
|
13
13
|
|
14
|
+
Add Nygma to your Gemfile and an initialiser to your Rails app, generating the
|
15
|
+
key and salt with `SecureRandom.hex(40)` and `SecureRandom.random_bytes(64)`.
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
# config/initializers/nygma.rb
|
19
|
+
|
20
|
+
Rails.application.config.encryptor = Nygma::Encryptor.crypt!(
|
21
|
+
'f46c1fb228aac44e55f82293a2341fb47c6f12c3721382ae7dbfe2e912941f59191efbc711f1ea5e',
|
22
|
+
'[d\x89\r\xF6\xEB7\x9C\n\x1F+\xCAG\xF1g\e\x9Bg\xA7-:iG\b4\x03\xED\xCE\x8F>OH\b\x80\x8F\xE3\x17j\x1D\xA6\b?3\xC4\xE4\x8D\x9Eb\xA5\xB0\xB6jS\xAD\v\xE4\xBB\xDB\xF7\xFC\xBC\x04\xFD\xE4'
|
23
|
+
)
|
24
|
+
```
|
25
|
+
|
26
|
+
You will now be able to specify attributes within your models that need
|
27
|
+
attribute level encryption,
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
class POTUSNuclearCode < ActiveRecord::Base
|
31
|
+
encrypt :launch_code, :auth_token
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
The world is now safe as the Chinese won't be able to grab US nuclear launch
|
36
|
+
codes from Hillary's email account! They'll be nicely encrypted and
|
37
|
+
persisted to disk.
|
38
|
+
|
39
|
+
### How it works
|
40
|
+
|
14
41
|
```ruby
|
15
42
|
crypt = Nygma::Encryptor.crypt!(
|
16
43
|
Nygma::Configuration.secure_key,
|
data/Rakefile
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
#!/usr/bin/env rake
|
1
2
|
begin
|
2
3
|
require 'bundler/setup'
|
3
4
|
rescue LoadError
|
@@ -14,8 +15,18 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
14
15
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
16
|
end
|
16
17
|
|
18
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
19
|
+
load 'rails/tasks/engine.rake'
|
17
20
|
|
21
|
+
Bundler::GemHelper.install_tasks
|
18
22
|
|
23
|
+
require 'rspec/core'
|
24
|
+
require 'rspec/core/rake_task'
|
19
25
|
|
20
|
-
|
26
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
27
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
28
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
29
|
+
# spec.rspec_opts = ['-cfs --backtrace']
|
30
|
+
end
|
21
31
|
|
32
|
+
task :default => :spec
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Nygma
|
2
|
+
|
3
|
+
module Encryptable
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def included _klass
|
7
|
+
_klass.class_eval do
|
8
|
+
include InstanceMethods
|
9
|
+
extend ClassMethods
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module InstanceMethods
|
15
|
+
|
16
|
+
protected
|
17
|
+
def encryptor
|
18
|
+
Rails.application.config.encryptor
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
module ClassMethods
|
24
|
+
|
25
|
+
def encrypt(*args)
|
26
|
+
args.each do |attribute|
|
27
|
+
unless has_column?(attribute)
|
28
|
+
Rails.logger.tagged('Nygma::Encryptable::encrypt') {
|
29
|
+
Rails.logger.info "Unable to encrypt missing attribute #{attribute} in #{self.name}, check your migrations!"
|
30
|
+
}
|
31
|
+
else
|
32
|
+
attr = "#{attribute}"
|
33
|
+
|
34
|
+
define_method("#{attr}") do
|
35
|
+
encryptor.decrypt(self[attribute]) if self[attribute]
|
36
|
+
end
|
37
|
+
|
38
|
+
define_method("#{attr}=") do |val|
|
39
|
+
encrypted_payload = encryptor.encrypt(val)
|
40
|
+
self[attribute] = encrypted_payload if encrypted_payload
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
def has_column?(attribute)
|
48
|
+
return true if self.column_names.include?(attribute.to_s)
|
49
|
+
|
50
|
+
false
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
data/lib/nygma/engine.rb
CHANGED
data/lib/nygma/version.rb
CHANGED
data/lib/nygma.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nygma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael de Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4.
|
19
|
+
version: 4.2.0
|
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
|
-
version: 4.
|
26
|
+
version: 4.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: attr_extras
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: guard-rspec
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +150,20 @@ dependencies:
|
|
122
150
|
- - ">="
|
123
151
|
- !ruby/object:Gem::Version
|
124
152
|
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: database_cleaner
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
125
167
|
- !ruby/object:Gem::Dependency
|
126
168
|
name: fuubar
|
127
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,8 +188,10 @@ files:
|
|
146
188
|
- MIT-LICENSE
|
147
189
|
- README.md
|
148
190
|
- Rakefile
|
191
|
+
- db/migrate/20150630040253_create_encryptable_test_models.rb
|
149
192
|
- lib/nygma.rb
|
150
193
|
- lib/nygma/configuration.rb
|
194
|
+
- lib/nygma/encryptable.rb
|
151
195
|
- lib/nygma/encryptor.rb
|
152
196
|
- lib/nygma/engine.rb
|
153
197
|
- lib/nygma/version.rb
|
@@ -162,9 +206,9 @@ require_paths:
|
|
162
206
|
- lib
|
163
207
|
required_ruby_version: !ruby/object:Gem::Requirement
|
164
208
|
requirements:
|
165
|
-
- - "
|
209
|
+
- - "~>"
|
166
210
|
- !ruby/object:Gem::Version
|
167
|
-
version:
|
211
|
+
version: 2.2.0
|
168
212
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
213
|
requirements:
|
170
214
|
- - ">="
|
@@ -172,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
216
|
version: '0'
|
173
217
|
requirements: []
|
174
218
|
rubyforge_project:
|
175
|
-
rubygems_version: 2.
|
219
|
+
rubygems_version: 2.4.5
|
176
220
|
signing_key:
|
177
221
|
specification_version: 4
|
178
222
|
summary: Gotham's very own Mr. Nygma, a Rails 4 Encryptor
|