encrypted_strings 0.0.5 → 0.1.0

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