shuber-attr_encrypted 1.0.5 → 1.0.6
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.
- data/CHANGELOG +5 -0
- data/README.markdown +3 -3
- data/lib/attr_encrypted.rb +6 -0
- data/lib/huberry/attr_encrypted/adapters/active_record.rb +7 -9
- data/lib/huberry/attr_encrypted/adapters/data_mapper.rb +10 -12
- data/lib/huberry/attr_encrypted/adapters/sequel.rb +3 -7
- data/test/active_record_test.rb +5 -1
- data/test/data_mapper_test.rb +5 -1
- data/test/sequel_test.rb +5 -1
- data/test/test_helper.rb +1 -2
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
2009-01-13 - Sean Huber (shuber@huberry.com)
|
2
|
+
* :marshal no longer defaults to true in ORM adapters
|
3
|
+
* Load gem dependencies
|
4
|
+
|
1
5
|
2009-01-12 - Sean Huber (shuber@huberry.com)
|
2
6
|
* Remove read_attribute and write_attribute methods - unnecessary
|
3
7
|
* ActiveRecord and DataMapper extensions are now "adapters"
|
@@ -6,6 +10,7 @@
|
|
6
10
|
* Add Sequel adapter
|
7
11
|
* Update DataMapper tests
|
8
12
|
* Update README
|
13
|
+
* Set attr_encrypted_options instead of overwriting the attr_encrypted method in adapters
|
9
14
|
|
10
15
|
2009-01-11 - Sean Huber (shuber@huberry.com)
|
11
16
|
* Update README
|
data/README.markdown
CHANGED
@@ -3,7 +3,7 @@ attr\_encrypted
|
|
3
3
|
|
4
4
|
Generates attr\_accessors that encrypt and decrypt attributes transparently
|
5
5
|
|
6
|
-
|
6
|
+
It works with ANY class, however, you get a few extra features when you're using it with ActiveRecord, DataMapper, or Sequel
|
7
7
|
|
8
8
|
|
9
9
|
Installation
|
@@ -267,7 +267,7 @@ If you're using this gem with ActiveRecord, you get a few extra features:
|
|
267
267
|
|
268
268
|
#### Default options ####
|
269
269
|
|
270
|
-
For your convenience, the `:encode`
|
270
|
+
For your convenience, the `:encode` option is set to true by default since you'll be storing everything in a database.
|
271
271
|
|
272
272
|
|
273
273
|
#### Dynamic find\_by\_ and scoped\_by\_ methods ####
|
@@ -291,7 +291,7 @@ NOTE: This only works if all records are encrypted with the same encryption key
|
|
291
291
|
|
292
292
|
### DataMapper and Sequel ###
|
293
293
|
|
294
|
-
Just like the default options for ActiveRecord, the `:encode`
|
294
|
+
Just like the default options for ActiveRecord, the `:encode` option is set to true by default since you'll be storing everything in a database.
|
295
295
|
|
296
296
|
|
297
297
|
Contact
|
data/lib/attr_encrypted.rb
CHANGED
@@ -4,21 +4,19 @@ if defined?(ActiveRecord)
|
|
4
4
|
module Adapters
|
5
5
|
module ActiveRecord
|
6
6
|
def self.extended(base)
|
7
|
+
base.attr_encrypted_options[:encode] = true
|
7
8
|
base.eigenclass_eval { alias_method_chain :method_missing, :attr_encrypted }
|
8
9
|
end
|
9
|
-
|
10
|
+
|
10
11
|
protected
|
11
|
-
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
# Also defines the attribute methods for db fields if they don't exist yet
|
12
|
+
|
13
|
+
# Ensures the attribute methods for db fields have been defined before calling the original
|
14
|
+
# <tt>attr_encrypted</tt> method
|
16
15
|
def attr_encrypted(*attrs)
|
17
16
|
define_attribute_methods
|
18
|
-
|
19
|
-
super *(attrs << options)
|
17
|
+
super
|
20
18
|
end
|
21
|
-
|
19
|
+
|
22
20
|
# Allows you to use dynamic methods like <tt>find_by_email</tt> or <tt>scoped_by_email</tt> for
|
23
21
|
# encrypted attributes
|
24
22
|
#
|
@@ -3,23 +3,21 @@ if defined?(DataMapper)
|
|
3
3
|
module AttrEncrypted
|
4
4
|
module Adapters
|
5
5
|
module DataMapper
|
6
|
-
def self.
|
7
|
-
base.
|
6
|
+
def self.extended(base)
|
7
|
+
base.eigenclass_eval do
|
8
|
+
alias_method :included_without_attr_encrypted, :included
|
9
|
+
alias_method :included, :included_with_attr_encrypted
|
10
|
+
end
|
8
11
|
end
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
# unless they've already been specified
|
14
|
-
def attr_encrypted(*attrs)
|
15
|
-
options = { :encode => true, :marshal => true }.merge(attrs.last.is_a?(Hash) ? attrs.pop : {})
|
16
|
-
super *(attrs << options)
|
17
|
-
end
|
12
|
+
|
13
|
+
def included_with_attr_encrypted(base)
|
14
|
+
included_without_attr_encrypted(base)
|
15
|
+
base.attr_encrypted_options[:encode] = true
|
18
16
|
end
|
19
17
|
end
|
20
18
|
end
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
24
|
-
DataMapper::Resource.
|
22
|
+
DataMapper::Resource.extend Huberry::AttrEncrypted::Adapters::DataMapper
|
25
23
|
end
|
@@ -3,13 +3,9 @@ if defined?(Sequel)
|
|
3
3
|
module AttrEncrypted
|
4
4
|
module Adapters
|
5
5
|
module Sequel
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def attr_encrypted(*attrs)
|
10
|
-
options = { :encode => true, :marshal => true }.merge(attrs.last.is_a?(Hash) ? attrs.pop : {})
|
11
|
-
super *(attrs << options)
|
12
|
-
end
|
6
|
+
def self.extended(base)
|
7
|
+
base.attr_encrypted_options[:encode] = true
|
8
|
+
end
|
13
9
|
end
|
14
10
|
end
|
15
11
|
end
|
data/test/active_record_test.rb
CHANGED
@@ -20,7 +20,7 @@ create_people_table
|
|
20
20
|
|
21
21
|
class Person < ActiveRecord::Base
|
22
22
|
attr_encrypted :email, :key => 'a secret key'
|
23
|
-
attr_encrypted :credentials, :key => Proc.new { |user| Huberry::Encryptor.encrypt(:value => user.salt, :key => 'some private key') }
|
23
|
+
attr_encrypted :credentials, :key => Proc.new { |user| Huberry::Encryptor.encrypt(:value => user.salt, :key => 'some private key') }, :marshal => true
|
24
24
|
|
25
25
|
def after_initialize
|
26
26
|
self.salt ||= Digest::SHA256.hexdigest((Time.now.to_i * rand(5)).to_s)
|
@@ -71,4 +71,8 @@ class ActiveRecordTest < Test::Unit::TestCase
|
|
71
71
|
assert_equal @person, Person.scoped_by_email_and_password('test@example.com', 'test').find(:first) rescue NoMethodError
|
72
72
|
end
|
73
73
|
|
74
|
+
def test_should_encode_by_default
|
75
|
+
assert Person.attr_encrypted_options[:encode]
|
76
|
+
end
|
77
|
+
|
74
78
|
end
|
data/test/data_mapper_test.rb
CHANGED
@@ -11,7 +11,7 @@ class Client
|
|
11
11
|
property :salt, String
|
12
12
|
|
13
13
|
attr_encrypted :email, :key => 'a secret key'
|
14
|
-
attr_encrypted :credentials, :key => Proc.new { |client| Huberry::Encryptor.encrypt(:value => client.salt, :key => 'some private key') }
|
14
|
+
attr_encrypted :credentials, :key => Proc.new { |client| Huberry::Encryptor.encrypt(:value => client.salt, :key => 'some private key') }, :marshal => true
|
15
15
|
|
16
16
|
def initialize(attrs = {})
|
17
17
|
super attrs
|
@@ -45,4 +45,8 @@ class DataMapperTest < Test::Unit::TestCase
|
|
45
45
|
assert Client.first.credentials.is_a?(Hash)
|
46
46
|
end
|
47
47
|
|
48
|
+
def test_should_encode_by_default
|
49
|
+
assert Client.attr_encrypted_options[:encode]
|
50
|
+
end
|
51
|
+
|
48
52
|
end
|
data/test/sequel_test.rb
CHANGED
@@ -12,7 +12,7 @@ end
|
|
12
12
|
|
13
13
|
class Human < Sequel::Model(:humans)
|
14
14
|
attr_encrypted :email, :key => 'a secret key'
|
15
|
-
attr_encrypted :credentials, :key => Proc.new { |human| Huberry::Encryptor.encrypt(:value => human.salt, :key => 'some private key') }
|
15
|
+
attr_encrypted :credentials, :key => Proc.new { |human| Huberry::Encryptor.encrypt(:value => human.salt, :key => 'some private key') }, :marshal => true
|
16
16
|
|
17
17
|
def after_initialize(attrs = {})
|
18
18
|
self.salt ||= Digest::SHA1.hexdigest((Time.now.to_i * rand(5)).to_s)
|
@@ -43,4 +43,8 @@ class SequelTest < Test::Unit::TestCase
|
|
43
43
|
assert Human.first.credentials.is_a?(Hash)
|
44
44
|
end
|
45
45
|
|
46
|
+
def test_should_encode_by_default
|
47
|
+
assert Human.attr_encrypted_options[:encode]
|
48
|
+
end
|
49
|
+
|
46
50
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shuber-attr_encrypted
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Huber
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-01-
|
12
|
+
date: 2009-01-13 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|