public
Rubygem
Description: Provides dead-simple string encryption/decryption syntax
Homepage: http://www.pluginaweek.org
Clone URL: git://github.com/pluginaweek/encrypted_strings.git
Remove dependency on active_support
Tag 0.1.0 release
obrie (author)
Mon Jul 07 18:34:31 -0700 2008
commit  3109ad51b4729bc7cc173aced0558b98d01f1747
tree    c64143abce18e7c560cf3ce2eb8279dfa4a7415d
parent  f6f9b0d9abb2031ff883d13115c512c6ac654ab1
...
1
2
 
 
 
 
3
4
5
...
1
2
3
4
5
6
7
8
9
0
@@ -1,5 +1,9 @@
0
 == master
0
 
0
+== 0.1.0 / 2008-07-06
0
+
0
+* Remove dependency on active_support
0
+
0
 == 0.0.5 / 2008-07-05
0
 
0
 * Add automatic stringification of salts for SHA encryption
...
5
6
7
8
 
9
10
11
...
5
6
7
 
8
9
10
11
0
@@ -5,7 +5,7 @@ require 'rake/contrib/sshpublisher'
0
 
0
 spec = Gem::Specification.new do |s|
0
   s.name              = 'encrypted_strings'
0
-  s.version           = '0.0.5'
0
+  s.version           = '0.1.0'
0
   s.platform          = Gem::Platform::RUBY
0
   s.summary           = 'Dead-simple string encryption/decryption syntax.'
0
   
...
50
51
52
53
54
 
 
55
56
57
58
 
 
59
60
61
62
 
 
63
64
65
...
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
 
 
 
 
 
 
 
 
94
95
96
...
50
51
52
 
 
53
54
55
56
 
 
57
58
59
60
 
 
61
62
63
64
65
...
79
80
81
 
 
 
 
 
 
 
 
 
 
 
 
82
83
84
85
86
87
88
89
90
91
92
0
@@ -50,16 +50,16 @@ module PluginAWeek #:nodoc:
0
     # found or the key could not decrypt the private key file.
0
     class AsymmetricEncryptor < Encryptor
0
       # The default private key to use during encryption.  Default is nil.
0
-      @@default_private_key_file = nil
0
-      cattr_accessor :default_private_key_file
0
+      @default_private_key_file = nil
0
+      class << self; attr_accessor :default_private_key_file; end
0
       
0
       # The default public key to use during encryption.  Default is nil.
0
-      @@default_public_key_file = nil
0
-      cattr_accessor :default_public_key_file
0
+      @default_public_key_file = nil
0
+      class << self; attr_accessor :default_public_key_file; end
0
       
0
       # The default algorithm to use.  Default is nil.
0
-      @@default_algorithm = nil
0
-      cattr_accessor :default_algorithm
0
+      @default_algorithm = nil
0
+      class << self; attr_accessor :default_algorithm; end
0
       
0
       # Private key used for decrypting data
0
       attr_reader :private_key_file
0
@@ -79,18 +79,14 @@ module PluginAWeek #:nodoc:
0
       # * +key+ - The key to use in the symmetric encryptor
0
       # * +algorithm+ - Algorithm to use symmetrically encrypted strings
0
       def initialize(options = {})
0
-        options = options.symbolize_keys
0
-        options.assert_valid_keys(
0
-          :private_key_file,
0
-          :public_key_file,
0
-          :key,
0
-          :algorithm
0
-        )
0
-        options.reverse_merge!(
0
-          :private_key_file => self.class.default_private_key_file,
0
-          :public_key_file => self.class.default_public_key_file,
0
-          :algorithm => self.class.default_algorithm
0
-        )
0
+        invalid_options = options.keys - [:private_key_file, :public_key_file, :key, :algorithm]
0
+        raise ArgumentError, "Unknown key(s): #{invalid_options.join(", ")}" unless invalid_options.empty?
0
+        
0
+        options = {
0
+          :private_key_file => AsymmetricEncryptor.default_private_key_file,
0
+          :public_key_file => AsymmetricEncryptor.default_public_key_file,
0
+          :algorithm => AsymmetricEncryptor.default_algorithm
0
+        }.merge(options)
0
         
0
         @public_key = @private_key = nil
0
         
...
188
189
190
191
192
 
 
193
194
195
...
188
189
190
 
 
191
192
193
194
195
0
@@ -188,8 +188,8 @@ module PluginAWeek #:nodoc:
0
           
0
           def encryptor_from_args(*args) #:nodoc:
0
             options = args.last.is_a?(Hash) ? args.pop : {}
0
-            mode = (args.first || :sha).to_sym
0
-            "PluginAWeek::EncryptedStrings::#{mode.to_s.classify}Encryptor".constantize.new(options)
0
+            mode = (args.first || :sha).to_s.gsub(/(?:^|_)(.)/) {$1.upcase}
0
+            PluginAWeek::EncryptedStrings.const_get("#{mode}Encryptor").new(options)
0
           end
0
       end
0
     end
...
29
30
31
32
33
 
 
34
35
36
...
38
39
40
41
42
43
 
 
 
 
44
45
46
...
29
30
31
 
 
32
33
34
35
36
...
38
39
40
 
 
 
41
42
43
44
45
46
47
0
@@ -29,8 +29,8 @@ module PluginAWeek #:nodoc:
0
     #   password == input                                   # => true
0
     class ShaEncryptor < Encryptor
0
       # The default salt value to use during encryption
0
-      @@default_salt = 'salt'
0
-      cattr_accessor :default_salt
0
+      @default_salt = 'salt'
0
+      class << self; attr_accessor :default_salt; end
0
       
0
       # The salt value to use for encryption
0
       attr_accessor :salt
0
@@ -38,9 +38,10 @@ module PluginAWeek #:nodoc:
0
       # Configuration options:
0
       # * +salt+ - Salt value to use for encryption
0
       def initialize(options = {})
0
-        options = options.symbolize_keys
0
-        options.assert_valid_keys(:salt)
0
-        options.reverse_merge!(:salt => self.class.default_salt)
0
+        invalid_options = options.keys - [:salt]
0
+        raise ArgumentError, "Unknown key(s): #{invalid_options.join(", ")}" unless invalid_options.empty?
0
+        
0
+        options = {:salt => ShaEncryptor.default_salt}.merge(options)
0
         
0
         self.salt = options[:salt].to_s
0
         
...
40
41
42
43
44
 
 
45
46
47
48
 
 
49
50
51
...
57
58
59
60
61
62
63
64
65
66
 
 
 
 
 
 
 
67
68
69
...
40
41
42
 
 
43
44
45
46
 
 
47
48
49
50
51
...
57
58
59
 
 
 
 
 
 
 
60
61
62
63
64
65
66
67
68
69
0
@@ -40,12 +40,12 @@ module PluginAWeek #:nodoc:
0
     # An exception will be raised if no key is specified.
0
     class SymmetricEncryptor < Encryptor
0
       # The default algorithm to use for encryption.  Default is DES
0
-      @@default_algorithm = 'DES-EDE3-CBC'
0
-      cattr_accessor :default_algorithm
0
+      @default_algorithm = 'DES-EDE3-CBC'
0
+      class << self; attr_accessor :default_algorithm; end
0
       
0
       # The default key to use.  Default is nil
0
-      @@default_key = nil
0
-      cattr_accessor :default_key
0
+      @default_key = nil
0
+      class << self; attr_accessor :default_key; end
0
       
0
       # The algorithm to use for encryption/decryption
0
       attr_accessor :algorithm
0
@@ -57,13 +57,13 @@ module PluginAWeek #:nodoc:
0
       # * +key+ - Private key
0
       # * +algorithm+ - Algorithm to use
0
       def initialize(options = {})
0
-        options = options.symbolize_keys
0
-        options.assert_valid_keys(
0
-          :key,
0
-          :algorithm
0
-        )
0
-        options.reverse_merge!(:key => self.class.default_key)
0
-        options[:algorithm] ||= self.class.default_algorithm
0
+        invalid_options = options.keys - [:key, :algorithm]
0
+        raise ArgumentError, "Unknown key(s): #{invalid_options.join(", ")}" unless invalid_options.empty?
0
+        
0
+        options = {
0
+          :key => SymmetricEncryptor.default_key,
0
+          :algorithm => SymmetricEncryptor.default_algorithm
0
+        }.merge(options)
0
         
0
         self.key = options[:key]
0
         raise NoKeyError if key.nil?
...
18
19
20
21
 
22
23
24
...
18
19
20
 
21
22
23
24
0
@@ -18,7 +18,7 @@ class AsymmetricEncryptorByDefaultTest < Test::Unit::TestCase
0
   end
0
   
0
   def test_should_use_the_default_algorithm
0
-    assert_equal 'DES-EDE3-CBC', @asymmetric_encryptor.default_algorithm
0
+    assert_equal 'DES-EDE3-CBC', @asymmetric_encryptor.algorithm
0
   end
0
   
0
   def test_should_not_have_a_key
...
49
50
51
 
 
52
53
54
...
49
50
51
52
53
54
55
56
0
@@ -49,6 +49,8 @@ class ShaEncryptorWithCustomSaltTest < Test::Unit::TestCase
0
 end
0
 
0
 class ShaEncryptorWithNonStringSaltTest < Test::Unit::TestCase
0
+  require 'time'
0
+  
0
   def setup
0
     @sha_encryptor = PluginAWeek::EncryptedStrings::ShaEncryptor.new(:salt => Time.parse('Tue Jan 01 00:00:00 UTC 2008'))
0
   end
...
1
2
3
4
5
6
...
1
 
 
2
3
4
0
@@ -1,6 +1,4 @@
0
 require 'test/unit'
0
-require 'rubygems'
0
-require 'active_support'
0
 
0
 $:.unshift(File.dirname(__FILE__) + '/../lib')
0
 require File.dirname(__FILE__) + '/../init'

Comments