encrypted_attributes 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,15 @@
1
+ *SVN*
2
+
3
+ *0.0.2* (September 26th, 2007)
4
+
5
+ * Move test fixtures out of the test application root directory
6
+
7
+ * Convert dos newlines to unix newlines
8
+
9
+ *0.0.1* (August 5th, 2007)
10
+
11
+ * Official public release
12
+
13
+ * Add documentation
14
+
15
+ * Refactor unit test names
data/README CHANGED
@@ -1,6 +1,6 @@
1
1
  = encrypted_attributes
2
2
 
3
- encrypted_attributes adds support for automatically encrypting ActiveRecord
3
+ +encrypted_attributes+ adds support for automatically encrypting ActiveRecord
4
4
  attributes.
5
5
 
6
6
  == Resources
@@ -15,7 +15,7 @@ Wiki
15
15
 
16
16
  Announcement
17
17
 
18
- * http://www.pluginaweek.org/
18
+ * http://www.pluginaweek.org
19
19
 
20
20
  Source
21
21
 
@@ -32,10 +32,12 @@ various models and various projects. encrypted_attributes, in association
32
32
  with the encrypted_strings plugin, helps make encrypting ActiveRecord
33
33
  attributes easier by automating the process.
34
34
 
35
- The options that #encrypts takes includes all of the encryption options for
35
+ The options that +encrypts+ takes includes all of the encryption options for
36
36
  the specific type of encryptor being used in the encrypted_strings plugin.
37
37
  Therefore, if setting the key for asymmetric encryption, this would be passed
38
- into the #encrypts method. Examples of this are shown below.
38
+ into the +encrypts+ method. Examples of this are show in the Usage section.
39
+
40
+ == Usage
39
41
 
40
42
  === SHA Encryption
41
43
 
@@ -87,9 +89,9 @@ With custom key files:
87
89
  The attribute which stores the unencrypted value is a "virtual" attribute.
88
90
  This means that there is no column with the same name in the database.
89
91
  Instead, the encrypted value is stored in the crypted attributed. By default,
90
- this is assumed to be "crypted_#{attr_name}". Therefore, if you are encrypting
92
+ this is assumed to be +crypted_#{attr_name}+. Therefore, if you are encrypting
91
93
  the "password" attribute, the encrypted value would be stored in
92
- "crypted_password".
94
+ +crypted_password+.
93
95
 
94
96
  The crypted attribute name can be customized like so:
95
97
 
@@ -105,12 +107,10 @@ the various options that can be passed in.
105
107
 
106
108
  == Testing
107
109
 
108
- This plugin requires that the plugin_test_helper gem be installed in order to
109
- run the unit tests. To install this gem:
110
-
111
- gem install plugin_test_helper
110
+ Before you can run any tests, the following gem must be installed:
111
+ * plugin_test_helper[http://wiki.pluginaweek.org/Plugin_test_helper]
112
112
 
113
113
  == Dependencies
114
114
 
115
115
  This plugin depends on the presence of the following plugins:
116
- # encrypted_strings - http://wiki.pluginaweek.org/Encrypted_strings
116
+ * encrypted_strings[http://wiki.pluginaweek.org/Encrypted_strings]
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rake/gempackagetask'
4
4
  require 'rake/contrib/sshpublisher'
5
5
 
6
6
  PKG_NAME = 'encrypted_attributes'
7
- PKG_VERSION = '0.0.1'
7
+ PKG_VERSION = '0.0.2'
8
8
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
9
9
  RUBY_FORGE_PROJECT = 'pluginaweek'
10
10
 
@@ -31,14 +31,14 @@ spec = Gem::Specification.new do |s|
31
31
  s.name = PKG_NAME
32
32
  s.version = PKG_VERSION
33
33
  s.platform = Gem::Platform::RUBY
34
- s.summary = ''
34
+ s.summary = 'Adds support for automatically encrypting ActiveRecord attributes'
35
35
 
36
- s.files = FileList['{lib,tasks,test}/**/*'].to_a + %w(init.rb MIT-LICENSE Rakefile README)
36
+ s.files = FileList['{lib,tasks,test}/**/*'].to_a + %w(CHANGELOG init.rb MIT-LICENSE Rakefile README)
37
37
  s.require_path = 'lib'
38
38
  s.autorequire = 'encrypted_attributes'
39
39
  s.has_rdoc = true
40
- s.add_dependency 'encrypted_strings', '>= 0.0.1'
41
40
  s.test_files = Dir['test/**/*_test.rb']
41
+ s.add_dependency 'encrypted_strings', '>= 0.0.1'
42
42
 
43
43
  s.author = 'Aaron Pfeifer, Neil Abraham'
44
44
  s.email = 'info@pluginaweek.org'
@@ -77,4 +77,4 @@ task :release => [:gem, :package] do
77
77
 
78
78
  ruby_forge.add_release(RUBY_FORGE_PROJECT, PKG_NAME, PKG_VERSION, file)
79
79
  end
80
- end
80
+ end
@@ -1,5 +1,5 @@
1
1
  module PluginAWeek #:nodoc:
2
- module EncryptedAttributes #:nodoc:
2
+ module EncryptedAttributes
3
3
  module Extensions #:nodoc:
4
4
  module Encryptor #:nodoc:
5
5
  def process_options(model, operation, options)
@@ -11,4 +11,4 @@ end
11
11
 
12
12
  PluginAWeek::EncryptedStrings::Encryptor.class_eval do
13
13
  extend PluginAWeek::EncryptedAttributes::Extensions::Encryptor
14
- end
14
+ end
@@ -1,28 +1,28 @@
1
- module PluginAWeek #:nodoc:
2
- module EncryptedAttributes #:nodoc:
3
- module Extensions #:nodoc:
4
- module ShaEncryptor
5
- # Adds support for using a salt that is generated based on the model and
6
- # stored in an attribute.
7
- def process_options(model, operation, options)
8
- if (salt_attr_name = options[:salt]) && (salt_attr_name == true || salt_attr_name.is_a?(Symbol))
9
- salt_attr_name = 'salt' if salt_attr_name == true
10
-
11
- if operation == :write
12
- salt_value = model.send("create_#{salt_attr_name}").to_s
13
- model.send("#{salt_attr_name}=", salt_value)
14
- else
15
- salt_value = model.send(salt_attr_name)
16
- end
17
-
18
- options[:salt] = salt_value
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
25
-
26
- PluginAWeek::EncryptedStrings::ShaEncryptor.class_eval do
27
- extend PluginAWeek::EncryptedAttributes::Extensions::ShaEncryptor
28
- end
1
+ module PluginAWeek #:nodoc:
2
+ module EncryptedAttributes
3
+ module Extensions #:nodoc:
4
+ module ShaEncryptor
5
+ # Adds support for using a salt that is generated based on the model and
6
+ # stored in an attribute.
7
+ def process_options(model, operation, options)
8
+ if (salt_attr_name = options[:salt]) && (salt_attr_name == true || salt_attr_name.is_a?(Symbol))
9
+ salt_attr_name = 'salt' if salt_attr_name == true
10
+
11
+ if operation == :write
12
+ salt_value = model.send("create_#{salt_attr_name}").to_s
13
+ model.send("#{salt_attr_name}=", salt_value)
14
+ else
15
+ salt_value = model.send(salt_attr_name)
16
+ end
17
+
18
+ options[:salt] = salt_value
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ PluginAWeek::EncryptedStrings::ShaEncryptor.class_eval do
27
+ extend PluginAWeek::EncryptedAttributes::Extensions::ShaEncryptor
28
+ end
@@ -1,73 +1,73 @@
1
- require 'encrypted_strings'
2
- require 'encrypted_attributes/extensions/encryptor'
3
- require 'encrypted_attributes/extensions/sha_encryptor'
4
-
5
- module PluginAWeek #:nodoc:
6
- module EncryptedAttributes
7
- def self.included(base) #:nodoc:
8
- base.extend(MacroMethods)
9
- end
10
-
11
- module MacroMethods
12
- # Encrypts the specified attribute.
13
- #
14
- # Configuration options:
15
- # * <tt>mode</tt> - The mode of encryption to use. Default is sha.
16
- # * <tt>crypted_name</tt> - The name of the attribute to store the crypted value in. Default is "crypted_#{attr_name}".
17
- #
18
- # For additional configuration options, see the individual encryptor class.
19
- def encrypts(attr_name, options = {})
20
- mode = options.delete(:mode) || :sha
21
- encryptor_class = "PluginAWeek::EncryptedStrings::#{mode.to_s.classify}Encryptor".constantize
22
-
23
- options.reverse_merge!(
24
- :crypted_name => "crypted_#{attr_name}"
25
- )
26
- crypted_attr_name = options.delete(:crypted_name)
27
- raise ArgumentError, 'Attribute name cannot be same as crypted name' if attr_name == crypted_attr_name
28
-
29
- # Creator accessor for the virtual attribute
30
- attr_accessor attr_name
31
-
32
- # Define the reader when reading the crypted value from the db
33
- crypted_var_name = "@#{crypted_attr_name}"
34
- define_method(crypted_attr_name) do
35
- if (value = read_attribute(crypted_attr_name)) && !value.encrypted?
36
- encryptor_options = options.dup
37
- encryptor_class.process_options(self, :read, encryptor_options)
38
- value.encryptor = encryptor_class.new(encryptor_options)
39
- end
40
-
41
- value
42
- end
43
-
44
- # Set the value immediately before validation takes place
45
- before_validation do |model|
46
- value = model.send(attr_name)
47
-
48
- if !value.blank?
49
- unless value.encrypted?
50
- encryptor_options = options.dup
51
- encryptor_class.process_options(model, :write, encryptor_options)
52
- value = value.encrypt(mode, encryptor_options)
53
- end
54
-
55
- model.send("#{crypted_attr_name}=", value)
56
- end
57
- end
58
-
59
- # After saving, be sure to reset the virtual attribute value. This also
60
- # supported resetting the confirmation field if, for example, the plugin
61
- # is being used for passwords
62
- after_save do |model|
63
- model.send("#{attr_name}=", nil)
64
- model.send("#{attr_name}_confirmation=", nil) if model.respond_to?("#{attr_name}_confirmation=")
65
- end
66
- end
67
- end
68
- end
69
- end
70
-
71
- ActiveRecord::Base.class_eval do
72
- include PluginAWeek::EncryptedAttributes
73
- end
1
+ require 'encrypted_strings'
2
+ require 'encrypted_attributes/extensions/encryptor'
3
+ require 'encrypted_attributes/extensions/sha_encryptor'
4
+
5
+ module PluginAWeek #:nodoc:
6
+ module EncryptedAttributes
7
+ def self.included(base) #:nodoc:
8
+ base.extend(MacroMethods)
9
+ end
10
+
11
+ module MacroMethods
12
+ # Encrypts the specified attribute.
13
+ #
14
+ # Configuration options:
15
+ # * +mode+ - The mode of encryption to use. Default is sha.
16
+ # * +crypted_name+ - The name of the attribute to store the crypted value in. Default is "crypted_#{attr_name}".
17
+ #
18
+ # For additional configuration options, see the individual encryptor class.
19
+ def encrypts(attr_name, options = {})
20
+ mode = options.delete(:mode) || :sha
21
+ encryptor_class = "PluginAWeek::EncryptedStrings::#{mode.to_s.classify}Encryptor".constantize
22
+
23
+ options.reverse_merge!(
24
+ :crypted_name => "crypted_#{attr_name}"
25
+ )
26
+ crypted_attr_name = options.delete(:crypted_name)
27
+ raise ArgumentError, 'Attribute name cannot be same as crypted name' if attr_name == crypted_attr_name
28
+
29
+ # Creator accessor for the virtual attribute
30
+ attr_accessor attr_name
31
+
32
+ # Define the reader when reading the crypted value from the db
33
+ crypted_var_name = "@#{crypted_attr_name}"
34
+ define_method(crypted_attr_name) do
35
+ if (value = read_attribute(crypted_attr_name)) && !value.encrypted?
36
+ encryptor_options = options.dup
37
+ encryptor_class.process_options(self, :read, encryptor_options)
38
+ value.encryptor = encryptor_class.new(encryptor_options)
39
+ end
40
+
41
+ value
42
+ end
43
+
44
+ # Set the value immediately before validation takes place
45
+ before_validation do |model|
46
+ value = model.send(attr_name)
47
+
48
+ if !value.blank?
49
+ unless value.encrypted?
50
+ encryptor_options = options.dup
51
+ encryptor_class.process_options(model, :write, encryptor_options)
52
+ value = value.encrypt(mode, encryptor_options)
53
+ end
54
+
55
+ model.send("#{crypted_attr_name}=", value)
56
+ end
57
+ end
58
+
59
+ # After saving, be sure to reset the virtual attribute value. This also
60
+ # supported resetting the confirmation field if, for example, the plugin
61
+ # is being used for passwords
62
+ after_save do |model|
63
+ model.send("#{attr_name}=", nil)
64
+ model.send("#{attr_name}_confirmation=", nil) if model.respond_to?("#{attr_name}_confirmation=")
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ ActiveRecord::Base.class_eval do
72
+ include PluginAWeek::EncryptedAttributes
73
+ end
File without changes
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper'))
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class EncryptedAttributesTest < Test::Unit::TestCase
4
4
  def setup
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper'))
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class EncryptorTest < Test::Unit::TestCase
4
4
  def test_should_not_make_any_changes_on_process_options
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper'))
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class ShaEncryptorTest < Test::Unit::TestCase
4
4
  def test_should_respond_to_process_options
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: encrypted_attributes
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2007-08-05 00:00:00 -04:00
8
- summary: ""
6
+ version: 0.0.2
7
+ date: 2007-09-26 00:00:00 -04:00
8
+ summary: Adds support for automatically encrypting ActiveRecord attributes
9
9
  require_paths:
10
10
  - lib
11
11
  email: info@pluginaweek.org
@@ -29,44 +29,44 @@ post_install_message:
29
29
  authors:
30
30
  - Aaron Pfeifer, Neil Abraham
31
31
  files:
32
+ - lib/encrypted_attributes.rb
32
33
  - lib/encrypted_attributes
33
34
  - lib/encrypted_attributes/extensions
34
- - lib/encrypted_attributes/extensions/encryptor.rb
35
35
  - lib/encrypted_attributes/extensions/sha_encryptor.rb
36
- - lib/encrypted_attributes.rb
36
+ - lib/encrypted_attributes/extensions/encryptor.rb
37
+ - test/test_helper.rb
38
+ - test/fixtures
37
39
  - test/app_root
40
+ - test/keys
41
+ - test/unit
42
+ - test/fixtures/users.yml
38
43
  - test/app_root/app
44
+ - test/app_root/db
39
45
  - test/app_root/app/models
40
- - test/app_root/app/models/asymmetric_user.rb
46
+ - test/app_root/app/models/sha_user_with_salt.rb
41
47
  - test/app_root/app/models/confirmed_sha_user.rb
48
+ - test/app_root/app/models/asymmetric_user.rb
42
49
  - test/app_root/app/models/sha_user.rb
43
50
  - test/app_root/app/models/sha_user_with_custom_crypted_attr.rb
51
+ - test/app_root/app/models/user.rb
44
52
  - test/app_root/app/models/sha_user_with_custom_salt.rb
45
- - test/app_root/app/models/sha_user_with_salt.rb
46
53
  - test/app_root/app/models/symmetric_user.rb
47
- - test/app_root/app/models/user.rb
48
- - test/app_root/db
49
54
  - test/app_root/db/migrate
50
55
  - test/app_root/db/migrate/001_create_users.rb
51
- - test/app_root/test
52
- - test/app_root/test/fixtures
53
- - test/app_root/test/fixtures/users.yml
54
- - test/keys
55
56
  - test/keys/private
56
57
  - test/keys/public
57
- - test/test_helper.rb
58
- - test/unit
59
58
  - test/unit/encrypted_attributes_test.rb
60
- - test/unit/encryptor_test.rb
61
59
  - test/unit/sha_encryptor_test.rb
60
+ - test/unit/encryptor_test.rb
61
+ - CHANGELOG
62
62
  - init.rb
63
63
  - MIT-LICENSE
64
64
  - Rakefile
65
65
  - README
66
66
  test_files:
67
67
  - test/unit/encrypted_attributes_test.rb
68
- - test/unit/encryptor_test.rb
69
68
  - test/unit/sha_encryptor_test.rb
69
+ - test/unit/encryptor_test.rb
70
70
  rdoc_options: []
71
71
 
72
72
  extra_rdoc_files: []