encrypted_store 0.2.0 → 0.2.1

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: 597b51a7a639daa48f0168cd455614d0badc530d
4
- data.tar.gz: 0c3ac74f182c8825f0bf8a2cb40b5c6c1636e221
3
+ metadata.gz: 1f550704fe41a4ad0a8c31b2fe2090ee30100908
4
+ data.tar.gz: fdb84fa8b34644b1b1119d42e342760309873db2
5
5
  SHA512:
6
- metadata.gz: f7abe54066eb6000e60e38ac7e6bf8df46f3b5e50d6d85957b38c56436dde3221e18730a4d21a7076729e96b673f887325856b419cda5be666b02c506168db56
7
- data.tar.gz: 8a280ee382d0de6e35f34bbe3b9ec683f57583bddb6a3cd823f0beb10c52e4348f3724f25344b220cb2d836172a0fb8b5c353b80944b24ab12f95a44df69d858
6
+ metadata.gz: e331f4483533fbf576989aeb3ef96ed5e3c6a43fc6d2d022501cdad49016a9e63d306add78701e4f19a0c014acb97283d99893064440ac98dc84fd6d55cdcfff
7
+ data.tar.gz: 1e64b1d0861ad3881d914411b79afe9b6e10467ea6b6a441981f3fe7d427219cc47e69fa258a2c3260fbb9383154ea28dfa5ae0b30a93e3928cb077da15d66b3
@@ -0,0 +1,132 @@
1
+ require 'yaml'
2
+
3
+ module EncryptedStore
4
+ class Config
5
+ # Putting this here instead of in Errors because I may move this into a
6
+ # separate gem.
7
+ class ConfigError < StandardError; end
8
+ class NotAddableError < ConfigError; end
9
+
10
+ class ProcArray < Array
11
+ def push(*procs)
12
+ raise ConfigError, "May only add blocks" unless procs.all? { |p| p.is_a?(Proc) }
13
+ super
14
+ end
15
+
16
+ def call(*args, &block)
17
+ map { |x| x.call(*args, &block) }
18
+ end
19
+ end
20
+
21
+ class UndefinedValue
22
+ def !
23
+ true
24
+ end
25
+ end
26
+
27
+ attr_reader :name
28
+
29
+ def initialize(name=nil, &block)
30
+ @name = name
31
+ define(&block) if block_given?
32
+ end
33
+
34
+ def define(&block)
35
+ case block.arity
36
+ when 0 then instance_eval(&block)
37
+ when 1 then block.call(self)
38
+ else raise ConfigError, 'invalid config block arity'
39
+ end
40
+ end
41
+
42
+ # Deep dup all the values.
43
+ def dup
44
+ super.tap do |new_config|
45
+ new_config.instance_variable_set(
46
+ :@_nested,
47
+ Hash[
48
+ _nested.map { |key, object|
49
+ [
50
+ key,
51
+ object.is_a?(Config) ? object.dup : object
52
+ ]
53
+ }
54
+ ]
55
+ )
56
+ end
57
+ end
58
+
59
+ def method_missing(meth, *args, &block)
60
+ meth_str = meth.to_s
61
+
62
+ if /^(\w+)\=$/.match(meth_str)
63
+ _set($1, *args, &block)
64
+ elsif args.length > 0 || block_given?
65
+ _add(meth, *args, &block)
66
+ elsif /^(\w+)\?$/.match(meth_str)
67
+ !!_get($1)
68
+ else
69
+ _get_or_create_namespace(meth)
70
+ end
71
+ end
72
+
73
+ def merge_hash!(hash)
74
+ hash.each { |k, v|
75
+ if v.is_a?(Hash)
76
+ send(k).merge_hash!(v)
77
+ else
78
+ send("#{k}=", v)
79
+ end
80
+ }
81
+
82
+ self
83
+ end
84
+
85
+ def merge_config_file!(file)
86
+ merge_hash!(YAML.load_file(file))
87
+ end
88
+
89
+ private
90
+ def _get(key)
91
+ _nested[key.to_sym]
92
+ end
93
+
94
+ def _get_or_create_namespace(key)
95
+ object = _get(key)
96
+
97
+ if object.is_a?(UndefinedValue)
98
+ object = _set(key, Config.new((name ? "#{name}." : '') + key.to_s))
99
+ end
100
+
101
+ object
102
+ end
103
+
104
+ def _set(key, *args, &block)
105
+ object = _args_to_object(*args, &block)
106
+ _nested[key.to_sym] = object
107
+ end
108
+
109
+ def _add(key, *args, &block)
110
+ raise NotAddableError, self.inspect if @_value && !@_value.is_a?(Array)
111
+ object = _args_to_object(*args, &block)
112
+ _set(key, object.is_a?(Proc) ? ProcArray.new : []) if !_get(key)
113
+ _get(key).push(object)
114
+ end
115
+
116
+ def _args_to_object(*args, &block)
117
+ if args.length == 1
118
+ args.first
119
+ elsif args.length > 1
120
+ args
121
+ elsif block_given?
122
+ block
123
+ else
124
+ raise ConfigError, 'must pass value or block'
125
+ end
126
+ end
127
+
128
+ def _nested
129
+ @_nested ||= Hash.new { |hash, key| hash[key] = UndefinedValue.new }
130
+ end
131
+ end # Config
132
+ end # EncryptedStore
@@ -2,7 +2,7 @@ require 'openssl'
2
2
  require 'json'
3
3
  require 'zlib'
4
4
 
5
- module Ribbon::EncryptedStore
5
+ module EncryptedStore
6
6
  class CryptoHash < Hash
7
7
  def initialize(data={})
8
8
  super()
@@ -147,4 +147,4 @@ module Ribbon::EncryptedStore
147
147
  self.class._calc_crc32(data)
148
148
  end
149
149
  end # CryptoHash
150
- end # Ribbon::EncryptedStore
150
+ end # EncryptedStore
@@ -1,4 +1,4 @@
1
- module Ribbon::EncryptedStore
1
+ module EncryptedStore
2
2
  module Errors
3
3
  class Error < StandardError; end
4
4
 
@@ -13,4 +13,4 @@ module Ribbon::EncryptedStore
13
13
  class InvalidKeySize < CryptoHashError; end
14
14
  class UnsupportedVersionError < CryptoHashError; end
15
15
  end # Errors
16
- end # Ribbon::EncryptedStore
16
+ end # EncryptedStore
@@ -1,7 +1,7 @@
1
- module Ribbon::EncryptedStore
1
+ module EncryptedStore
2
2
  class Instance
3
3
  def config(&block)
4
- (@__config ||= Ribbon::Config.new).tap { |config|
4
+ (@__config ||= Config.new).tap { |config|
5
5
  if block_given?
6
6
  config.define(&block)
7
7
  end
@@ -27,4 +27,4 @@ module Ribbon::EncryptedStore
27
27
  (@_decrypted_keys ||= {})[key_id] ||= key_model.find(key_id).decrypted_key
28
28
  end
29
29
  end # Instance
30
- end # Ribbon::EncryptedStore
30
+ end # EncryptedStore
@@ -1,7 +1,7 @@
1
1
  require 'securerandom'
2
2
  require 'base64'
3
3
 
4
- module Ribbon::EncryptedStore
4
+ module EncryptedStore
5
5
  module Mixins
6
6
  module ActiveRecordMixin
7
7
  class EncryptionKey < ActiveRecord::Base
@@ -74,4 +74,4 @@ module Ribbon::EncryptedStore
74
74
  end # EncryptionKey
75
75
  end # ActiveRecordMixin
76
76
  end # Mixins
77
- end # Ribbon::EncryptedStore
77
+ end # EncryptedStore
@@ -1,6 +1,6 @@
1
1
  require 'securerandom'
2
2
 
3
- module Ribbon::EncryptedStore
3
+ module EncryptedStore
4
4
  module Mixins
5
5
  module ActiveRecordMixin
6
6
  class EncryptionKeySalt < ActiveRecord::Base
@@ -25,4 +25,4 @@ module Ribbon::EncryptedStore
25
25
  end # EncryptionKeySalt
26
26
  end # ActiveRecordMixin
27
27
  end # Mixins
28
- end # Ribbon::EncryptedStore
28
+ end # EncryptedStore
@@ -1,10 +1,10 @@
1
1
  require 'securerandom'
2
2
 
3
- module Ribbon::EncryptedStore
3
+ module EncryptedStore
4
4
  module Mixins
5
5
  module ActiveRecordMixin
6
- autoload(:EncryptionKeySalt, 'ribbon/encrypted_store/mixins/active_record_mixin/encryption_key_salt')
7
- autoload(:EncryptionKey, 'ribbon/encrypted_store/mixins/active_record_mixin/encryption_key')
6
+ autoload(:EncryptionKeySalt, 'encrypted_store/mixins/active_record_mixin/encryption_key_salt')
7
+ autoload(:EncryptionKey, 'encrypted_store/mixins/active_record_mixin/encryption_key')
8
8
 
9
9
  class << self
10
10
  def included(base)
@@ -91,8 +91,8 @@ module Ribbon::EncryptedStore
91
91
  self.encryption_key_id = record.encryption_key_id if record && record.encryption_key_id
92
92
  end
93
93
 
94
- iter_mag = Ribbon::EncryptedStore.config.iteration_magnitude? ?
95
- Ribbon::EncryptedStore.config.iteration_magnitude :
94
+ iter_mag = EncryptedStore.config.iteration_magnitude? ?
95
+ EncryptedStore.config.iteration_magnitude :
96
96
  -1
97
97
 
98
98
  @_reencrypting = false
@@ -105,4 +105,4 @@ module Ribbon::EncryptedStore
105
105
  end
106
106
  end # ActiveRecordMixin
107
107
  end # Mixins
108
- end # Ribbon::EncryptedStore
108
+ end # EncryptedStore
@@ -0,0 +1,5 @@
1
+ module EncryptedStore
2
+ module Mixins
3
+ autoload(:ActiveRecordMixin, 'encrypted_store/mixins/active_record_mixin')
4
+ end # Mixins
5
+ end # EncryptedStore
@@ -0,0 +1,21 @@
1
+ require 'encrypted_store'
2
+ require 'rails'
3
+ require 'rails/generators'
4
+
5
+ module EncryptedStore
6
+ class Railtie < Rails::Railtie
7
+ railtie_name :encrypted_store
8
+
9
+ rake_tasks do
10
+ Dir[
11
+ File.expand_path("../../tasks", __FILE__) + '/**/*.rake'
12
+ ].each { |rake_file| load rake_file }
13
+ end
14
+
15
+ generators do
16
+ Dir[
17
+ File.expand_path("../../generators", __FILE__) + '/**/*.rb'
18
+ ].each { |generator| require generator }
19
+ end
20
+ end # Railtie
21
+ end # EncryptedStore
@@ -0,0 +1,3 @@
1
+ module EncryptedStore
2
+ VERSION = '0.2.1'
3
+ end # EncryptedStore
@@ -0,0 +1,28 @@
1
+ require 'encrypted_store/version'
2
+
3
+ module EncryptedStore
4
+ require 'encrypted_store/railtie' if defined?(Rails)
5
+ autoload(:Config, 'encrypted_store/config')
6
+ autoload(:CryptoHash, 'encrypted_store/crypto_hash')
7
+ autoload(:Instance, 'encrypted_store/instance')
8
+ autoload(:Errors, 'encrypted_store/errors')
9
+ autoload(:Mixins, 'encrypted_store/mixins')
10
+
11
+ class << self
12
+ def included(base)
13
+ if defined?(ActiveRecord) && base < ActiveRecord::Base
14
+ base.send(:include, Mixins::ActiveRecordMixin)
15
+ else
16
+ raise Errors::UnsupportedModelError
17
+ end
18
+ end
19
+
20
+ def method_missing(meth, *args, &block)
21
+ instance.send(meth, *args, &block)
22
+ end
23
+
24
+ def instance
25
+ @__instance ||= Instance.new
26
+ end
27
+ end # Class Methods
28
+ end # EncryptedStore
@@ -1,4 +1,4 @@
1
- module Ribbon::EncryptedStore
1
+ module EncryptedStore
2
2
  module Generators
3
3
  class EncryptTableGenerator < Rails::Generators::Base
4
4
  source_root File.expand_path('../templates', __FILE__)
@@ -9,4 +9,4 @@ module Ribbon::EncryptedStore
9
9
  end
10
10
  end # EncryptTableGenerator
11
11
  end # Generators
12
- end # Ribbon::EncryptedStore
12
+ end # EncryptedStore
@@ -1,6 +1,6 @@
1
1
  require 'rails/generators/active_record'
2
2
 
3
- module Ribbon::EncryptedStore
3
+ module EncryptedStore
4
4
  module Generators
5
5
  class InstallGenerator < Rails::Generators::Base
6
6
  include Rails::Generators::Migration
@@ -23,4 +23,4 @@ module Ribbon::EncryptedStore
23
23
  end
24
24
  end # InstallEncryptedStoreGenerator
25
25
  end # Generators
26
- end # Ribbon::EncryptedStore
26
+ end # EncryptedStore
@@ -1,6 +1,6 @@
1
- require 'ribbon/encrypted_store'
1
+ require 'encrypted_store'
2
2
 
3
- Ribbon::EncryptedStore.config {
3
+ EncryptedStore.config {
4
4
  encrypt_key { |dek| dek }
5
5
  decrypt_key { |dek| dek }
6
- }
6
+ }
@@ -1,6 +1,6 @@
1
1
  require 'rails/generators/active_record'
2
2
 
3
- module Ribbon::EncryptedStore
3
+ module EncryptedStore
4
4
  module Generators
5
5
  module Upgrade
6
6
  class ZeroOneFiveGenerator < Rails::Generators::Base
@@ -21,4 +21,4 @@ module Ribbon::EncryptedStore
21
21
  end # ZeroOneFiveGenerator
22
22
  end # Upgrade
23
23
  end # Generators
24
- end # Ribbon::EncryptedStore
24
+ end # EncryptedStore
@@ -1,4 +1,4 @@
1
- require 'ribbon/encrypted_store'
1
+ require 'encrypted_store'
2
2
 
3
3
  namespace :encrypted_store do
4
4
  task :new_key, [:custom_key] => :environment do |t, args|
@@ -16,4 +16,4 @@ namespace :encrypted_store do
16
16
  new_primary_key = EncryptedStore::Mixins::ActiveRecordMixin::EncryptionKey.rotate_keys
17
17
  puts "Retired all key_ids and reencrypted records with new primary key: #{new_primary_key.id}"
18
18
  end
19
- end
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: encrypted_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Honer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-10-03 00:00:00.000000000 Z
12
+ date: 2016-01-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bcrypt
@@ -31,20 +31,6 @@ dependencies:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 3.1.3
34
- - !ruby/object:Gem::Dependency
35
- name: ribbon-config
36
- requirement: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 0.1.0
41
- type: :runtime
42
- prerelease: false
43
- version_requirements: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 0.1.0
48
34
  - !ruby/object:Gem::Dependency
49
35
  name: database_cleaner
50
36
  requirement: !ruby/object:Gem::Requirement
@@ -117,12 +103,23 @@ dependencies:
117
103
  version: 4.0.0
118
104
  description: Provides the EncryptedStore mixin
119
105
  email:
120
- - robert@ribbonpayments.com
121
- - kayvon@ribbonpayments.com
106
+ - robert@payout.com
107
+ - kayvon@payout.com
122
108
  executables: []
123
109
  extensions: []
124
110
  extra_rdoc_files: []
125
111
  files:
112
+ - lib/encrypted_store.rb
113
+ - lib/encrypted_store/config.rb
114
+ - lib/encrypted_store/crypto_hash.rb
115
+ - lib/encrypted_store/errors.rb
116
+ - lib/encrypted_store/instance.rb
117
+ - lib/encrypted_store/mixins.rb
118
+ - lib/encrypted_store/mixins/active_record_mixin.rb
119
+ - lib/encrypted_store/mixins/active_record_mixin/encryption_key.rb
120
+ - lib/encrypted_store/mixins/active_record_mixin/encryption_key_salt.rb
121
+ - lib/encrypted_store/railtie.rb
122
+ - lib/encrypted_store/version.rb
126
123
  - lib/generators/encrypted_store/encrypt_table/encrypt_table_generator.rb
127
124
  - lib/generators/encrypted_store/install/install_generator.rb
128
125
  - lib/generators/encrypted_store/install/templates/create_encryption_key_salts.rb
@@ -131,18 +128,8 @@ files:
131
128
  - lib/generators/encrypted_store/upgrade/ZeroOneFive/templates/upgrade_encryption_key_salts_to_015.rb
132
129
  - lib/generators/encrypted_store/upgrade/ZeroOneFive/templates/upgrade_encryption_keys_to_015.rb
133
130
  - lib/generators/encrypted_store/upgrade/ZeroOneFive/zero_one_five_generator.rb
134
- - lib/ribbon/encrypted_store.rb
135
- - lib/ribbon/encrypted_store/crypto_hash.rb
136
- - lib/ribbon/encrypted_store/errors.rb
137
- - lib/ribbon/encrypted_store/instance.rb
138
- - lib/ribbon/encrypted_store/mixins.rb
139
- - lib/ribbon/encrypted_store/mixins/active_record_mixin.rb
140
- - lib/ribbon/encrypted_store/mixins/active_record_mixin/encryption_key.rb
141
- - lib/ribbon/encrypted_store/mixins/active_record_mixin/encryption_key_salt.rb
142
- - lib/ribbon/encrypted_store/railtie.rb
143
- - lib/ribbon/encrypted_store/version.rb
144
131
  - lib/tasks/encrypted_store.rake
145
- homepage: http://github.com/ribbon/encrypted_store
132
+ homepage: http://github.com/payout/encrypted_store
146
133
  licenses:
147
134
  - BSD
148
135
  metadata: {}
@@ -1,5 +0,0 @@
1
- module Ribbon::EncryptedStore
2
- module Mixins
3
- autoload(:ActiveRecordMixin, 'ribbon/encrypted_store/mixins/active_record_mixin')
4
- end # Mixins
5
- end # Ribbon::EncryptedStore
@@ -1,23 +0,0 @@
1
- require 'ribbon/encrypted_store'
2
- require 'rails'
3
- require 'rails/generators'
4
-
5
- module Ribbon
6
- module EncryptedStore
7
- class Railtie < Rails::Railtie
8
- railtie_name :encrypted_store
9
-
10
- rake_tasks do
11
- Dir[
12
- File.expand_path("../../../tasks", __FILE__) + '/**/*.rake'
13
- ].each { |rake_file| load rake_file }
14
- end
15
-
16
- generators do
17
- Dir[
18
- File.expand_path("../../../generators", __FILE__) + '/**/*.rb'
19
- ].each { |generator| require generator }
20
- end
21
- end # Railtie
22
- end # EncryptedStore
23
- end # Ribbon
@@ -1,5 +0,0 @@
1
- module Ribbon
2
- module EncryptedStore
3
- VERSION = '0.2.0'
4
- end # EncryptedStore
5
- end # Ribbon
@@ -1,33 +0,0 @@
1
- require 'ribbon/encrypted_store/version'
2
- require 'ribbon/config'
3
-
4
- module Ribbon
5
- module EncryptedStore
6
- require 'ribbon/encrypted_store/railtie' if defined?(Rails)
7
- autoload(:CryptoHash, 'ribbon/encrypted_store/crypto_hash')
8
- autoload(:Instance, 'ribbon/encrypted_store/instance')
9
- autoload(:Errors, 'ribbon/encrypted_store/errors')
10
- autoload(:Mixins, 'ribbon/encrypted_store/mixins')
11
-
12
- class << self
13
- def included(base)
14
- if defined?(ActiveRecord) && base < ActiveRecord::Base
15
- base.send(:include, Mixins::ActiveRecordMixin)
16
- else
17
- raise Errors::UnsupportedModelError
18
- end
19
- end
20
-
21
- def method_missing(meth, *args, &block)
22
- instance.send(meth, *args, &block)
23
- end
24
-
25
- def instance
26
- @__instance ||= Instance.new
27
- end
28
- end # Class Methods
29
- end # EncryptedStore
30
- end # Ribbon
31
-
32
- # Create a shortcut to the module
33
- EncryptedStore = Ribbon::EncryptedStore