encrypted_strings 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,23 +1,25 @@
1
- *SVN*
1
+ == master
2
2
 
3
- *0.0.4* (May 5th, 2008)
3
+ == 0.0.5 / 2008-07-05
4
+
5
+ * Add automatic stringification of salts for SHA encryption
6
+ * Fix not resetting the encryptor after calling decrypt!
7
+
8
+ == 0.0.4 / 2008-05-05
4
9
 
5
10
  * Updated documentation
6
11
 
7
- *0.0.3* (September 18th, 2007)
12
+ == 0.0.3 / 2007-09-18
8
13
 
9
14
  * Remove gem dependency on activesupport
10
15
 
11
- *0.0.2* (August 23rd, 2007)
16
+ == 0.0.2 / 2007-08-23
12
17
 
13
18
  * Fix not allowing the decryption mode to be overriden if the string already has an encryptor
14
-
15
19
  * Convert dos newlines to unix newlines
16
20
 
17
- *0.0.1* (August 5th, 2007)
21
+ == 0.0.1 / 2007-08-05
18
22
 
19
23
  * Official public release
20
-
21
24
  * Add api documentation
22
-
23
25
  * Refactor unit test names
File without changes
@@ -4,21 +4,21 @@
4
4
 
5
5
  == Resources
6
6
 
7
- Wiki
8
-
9
- * http://wiki.pluginaweek.org/Encrypted_strings
10
-
11
7
  API
12
8
 
13
9
  * http://api.pluginaweek.org/encrypted_strings
14
10
 
11
+ Bugs
12
+
13
+ * http://pluginaweek.lighthouseapp.com/projects/13270-encrypted_strings
14
+
15
15
  Development
16
16
 
17
- * http://dev.pluginaweek.org/browse/trunk/encrypted_strings
17
+ * http://github.com/pluginaweek/encrypted_strings
18
18
 
19
19
  Source
20
20
 
21
- * http://svn.pluginaweek.org/trunk/encrypted_strings
21
+ * git://github.com/pluginaweek/encrypted_strings.git
22
22
 
23
23
  == Description
24
24
 
@@ -85,4 +85,4 @@ None.
85
85
 
86
86
  == References
87
87
 
88
- * Rick Olson - sentry[http://svn.techno-weenie.net/projects/plugins/sentry]
88
+ * Rick Olson - sentry[http://github.com/technoweenie/sentry]
data/Rakefile CHANGED
@@ -3,45 +3,54 @@ require 'rake/rdoctask'
3
3
  require 'rake/gempackagetask'
4
4
  require 'rake/contrib/sshpublisher'
5
5
 
6
- PKG_NAME = 'encrypted_strings'
7
- PKG_VERSION = '0.0.4'
8
- PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
9
- RUBY_FORGE_PROJECT = 'pluginaweek'
10
-
11
- desc 'Default: run unit tests.'
6
+ spec = Gem::Specification.new do |s|
7
+ s.name = 'encrypted_strings'
8
+ s.version = '0.0.5'
9
+ s.platform = Gem::Platform::RUBY
10
+ s.summary = 'Dead-simple string encryption/decryption syntax.'
11
+
12
+ s.files = FileList['{lib,test}/**/*'].to_a + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc)
13
+ s.require_path = 'lib'
14
+ s.has_rdoc = true
15
+ s.test_files = Dir['test/**/*_test.rb']
16
+
17
+ s.author = 'Aaron Pfeifer'
18
+ s.email = 'aaron@pluginaweek.org'
19
+ s.homepage = 'http://www.pluginaweek.org'
20
+ s.rubyforge_project = 'pluginaweek'
21
+ end
22
+
23
+ desc 'Default: run all tests.'
12
24
  task :default => :test
13
25
 
14
- desc 'Test the encrypted_strings plugin.'
26
+ desc "Test the #{spec.name} plugin."
15
27
  Rake::TestTask.new(:test) do |t|
16
28
  t.libs << 'lib'
17
- t.pattern = 'test/**/*_test.rb'
29
+ t.test_files = spec.test_files
18
30
  t.verbose = true
19
31
  end
20
32
 
21
- desc 'Generate documentation for the encrypted_strings plugin.'
22
- Rake::RDocTask.new(:rdoc) do |rdoc|
23
- rdoc.rdoc_dir = 'rdoc'
24
- rdoc.title = 'EncryptedStrings'
25
- rdoc.options << '--line-numbers' << '--inline-source'
26
- rdoc.rdoc_files.include('README')
27
- rdoc.rdoc_files.include('lib/**/*.rb')
33
+ begin
34
+ require 'rcov/rcovtask'
35
+ namespace :test do
36
+ desc "Test the #{spec.name} plugin with Rcov."
37
+ Rcov::RcovTask.new(:rcov) do |t|
38
+ t.libs << 'lib'
39
+ t.test_files = spec.test_files
40
+ t.rcov_opts << '--exclude="^(?!lib/)"'
41
+ t.verbose = true
42
+ end
43
+ end
44
+ rescue LoadError
28
45
  end
29
46
 
30
- spec = Gem::Specification.new do |s|
31
- s.name = PKG_NAME
32
- s.version = PKG_VERSION
33
- s.platform = Gem::Platform::RUBY
34
- s.summary = 'Dead-simple string encryption/decryption syntax.'
35
-
36
- s.files = FileList['{lib,test}/**/*'].to_a + %w(CHANGELOG init.rb MIT-LICENSE Rakefile README)
37
- s.require_path = 'lib'
38
- s.autorequire = 'encrypted_strings'
39
- s.has_rdoc = true
40
- s.test_files = Dir['test/**/*_test.rb']
41
-
42
- s.author = 'Aaron Pfeifer'
43
- s.email = 'aaron@pluginaweek.org'
44
- s.homepage = 'http://www.pluginaweek.org'
47
+ desc "Generate documentation for the #{spec.name} plugin."
48
+ Rake::RDocTask.new(:rdoc) do |rdoc|
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = spec.name
51
+ rdoc.template = '../rdoc_template.rb'
52
+ rdoc.options << '--line-numbers'
53
+ rdoc.rdoc_files.include('README.rdoc', 'CHANGELOG.rdoc', 'LICENSE', 'lib/**/*.rb')
45
54
  end
46
55
 
47
56
  Rake::GemPackageTask.new(spec) do |p|
@@ -50,30 +59,30 @@ Rake::GemPackageTask.new(spec) do |p|
50
59
  p.need_zip = true
51
60
  end
52
61
 
53
- desc 'Publish the beta gem'
62
+ desc 'Publish the beta gem.'
54
63
  task :pgem => [:package] do
55
- Rake::SshFilePublisher.new('aaron@pluginaweek.org', '/home/aaron/gems.pluginaweek.org/public/gems', 'pkg', "#{PKG_FILE_NAME}.gem").upload
64
+ Rake::SshFilePublisher.new('aaron@pluginaweek.org', '/home/aaron/gems.pluginaweek.org/public/gems', 'pkg', "#{spec.name}-#{spec.version}.gem").upload
56
65
  end
57
66
 
58
- desc 'Publish the API documentation'
67
+ desc 'Publish the API documentation.'
59
68
  task :pdoc => [:rdoc] do
60
- Rake::SshDirPublisher.new('aaron@pluginaweek.org', "/home/aaron/api.pluginaweek.org/public/#{PKG_NAME}", 'rdoc').upload
69
+ Rake::SshDirPublisher.new('aaron@pluginaweek.org', "/home/aaron/api.pluginaweek.org/public/#{spec.name}", 'rdoc').upload
61
70
  end
62
71
 
63
72
  desc 'Publish the API docs and gem'
64
- task :publish => [:pdoc, :release]
73
+ task :publish => [:pgem, :pdoc, :release]
65
74
 
66
75
  desc 'Publish the release files to RubyForge.'
67
76
  task :release => [:gem, :package] do
68
77
  require 'rubyforge'
69
78
 
70
- ruby_forge = RubyForge.new
79
+ ruby_forge = RubyForge.new.configure
71
80
  ruby_forge.login
72
81
 
73
- %w( gem tgz zip ).each do |ext|
74
- file = "pkg/#{PKG_FILE_NAME}.#{ext}"
82
+ %w(gem tgz zip).each do |ext|
83
+ file = "pkg/#{spec.name}-#{spec.version}.#{ext}"
75
84
  puts "Releasing #{File.basename(file)}..."
76
85
 
77
- ruby_forge.add_release(RUBY_FORGE_PROJECT, PKG_NAME, PKG_VERSION, file)
86
+ ruby_forge.add_release(spec.rubyforge_project, spec.name, spec.version, file)
78
87
  end
79
88
  end
@@ -44,7 +44,7 @@ module PluginAWeek #:nodoc:
44
44
  # default values will be used. You can override the default values like so:
45
45
  #
46
46
  # password = "INy95irZ8AlHmvc6ZAF/ARsTpbqPIB/4bEAKKOebjsayB7NYWtIzpswvzxqf\nNJ5yyuvxfMODrcg7RimEMFkFlg==\n"
47
- # password.decrypt(:asymmetric, :public_key_file => "./encrypted_private.key", :key => "secret") # => "shhhh"
47
+ # password.decrypt(:asymmetric, :public_key_file => "./encrypted_public.key", :key => "secret") # => "shhhh"
48
48
  #
49
49
  # An exception will be raised if either the private key file could not be
50
50
  # found or the key could not decrypt the private key file.
@@ -61,9 +61,16 @@ module PluginAWeek #:nodoc:
61
61
  @@default_algorithm = nil
62
62
  cattr_accessor :default_algorithm
63
63
 
64
- attr_reader :private_key_file
65
- attr_reader :public_key_file
64
+ # Private key used for decrypting data
65
+ attr_reader :private_key_file
66
+
67
+ # Public key used for encrypting data
68
+ attr_reader :public_key_file
69
+
70
+ # The algorithm to use if the key files are encrypted themselves
66
71
  attr_accessor :algorithm
72
+
73
+ # The key used during symmetric decryption of the key files
67
74
  attr_accessor :key
68
75
 
69
76
  # Configuration options:
@@ -80,22 +87,23 @@ module PluginAWeek #:nodoc:
80
87
  :algorithm
81
88
  )
82
89
  options.reverse_merge!(
83
- :private_key_file => @@default_private_key_file,
84
- :public_key_file => @@default_public_key_file,
85
- :algorithm => @@default_algorithm
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
86
93
  )
87
94
 
88
95
  @public_key = @private_key = nil
96
+
89
97
  self.key = options[:key]
90
98
  self.algorithm = options[:algorithm]
91
-
92
99
  self.private_key_file = options[:private_key_file]
93
100
  self.public_key_file = options[:public_key_file]
94
101
 
95
102
  super()
96
103
  end
97
104
 
98
- # Encrypts the given data
105
+ # Encrypts the given data. If no public key file has been specified, then
106
+ # a NoPublicKeyError will be raised.
99
107
  def encrypt(data)
100
108
  raise NoPublicKeyError, "Public key file: #{public_key_file}" unless public?
101
109
 
@@ -103,7 +111,8 @@ module PluginAWeek #:nodoc:
103
111
  Base64.encode64(encrypted_data)
104
112
  end
105
113
 
106
- # Decrypts the given data
114
+ # Decrypts the given data. If no private key file has been specified, then
115
+ # a NoPrivateKeyError will be raised.
107
116
  def decrypt(data)
108
117
  raise NoPrivateKeyError, "Private key file: #{private_key_file}" unless private?
109
118
 
@@ -121,23 +130,24 @@ module PluginAWeek #:nodoc:
121
130
  @public_key_file = file and load_public_key
122
131
  end
123
132
 
124
- # Is this string encrypted using a public key?
133
+ # Does this encryptor have a public key available?
125
134
  def public?
126
- return true unless @public_key.nil?
135
+ return true if @public_key
127
136
 
128
137
  load_public_key
129
138
  !@public_key.nil?
130
139
  end
131
140
 
132
- # Is this string encrypted using a private key?
141
+ # Does this encryptor have a private key available?
133
142
  def private?
134
- return true unless @private_key.nil?
143
+ return true if @private_key
135
144
 
136
145
  load_private_key
137
146
  !@private_key.nil?
138
147
  end
139
148
 
140
149
  private
150
+ # Loads the private key from the configured file
141
151
  def load_private_key
142
152
  @private_rsa = nil
143
153
 
@@ -146,6 +156,7 @@ module PluginAWeek #:nodoc:
146
156
  end
147
157
  end
148
158
 
159
+ # Loads the public key from the configured file
149
160
  def load_public_key
150
161
  @public_rsa = nil
151
162
 
@@ -154,7 +165,7 @@ module PluginAWeek #:nodoc:
154
165
  end
155
166
  end
156
167
 
157
- # Retrieves private RSA from the private key
168
+ # Retrieves the private RSA from the private key
158
169
  def private_rsa
159
170
  if key
160
171
  private_key = @private_key.decrypt(:symmetric, :key => key, :algorithm => algorithm)
@@ -1,7 +1,8 @@
1
1
  module PluginAWeek #:nodoc:
2
2
  module EncryptedStrings
3
- # Represents an encryptor for strings. Certain encryption algorithms
4
- # do not allow for strings to be decrypted.
3
+ # Represents the base class for all encryptors. By default, all encryptors
4
+ # are assumed to be able to decrypt strings. Note, however, that certain
5
+ # encryption algorithms do not allow decryption.
5
6
  class Encryptor
6
7
  # Can this string be decrypted? Default is true.
7
8
  def can_decrypt?
@@ -110,7 +110,9 @@ module PluginAWeek #:nodoc:
110
110
  # password.decrypt!(:symmetric, :key => 'my_key') # => "shhhh"
111
111
  # password # => "shhhh"
112
112
  def decrypt!(*args)
113
- replace(decrypt(*args))
113
+ value = replace(decrypt(*args))
114
+ self.encryptor = nil
115
+ value
114
116
  end
115
117
 
116
118
  # Can this string be decrypted? Strings can only be decrypted if they
@@ -32,6 +32,7 @@ module PluginAWeek #:nodoc:
32
32
  @@default_salt = 'salt'
33
33
  cattr_accessor :default_salt
34
34
 
35
+ # The salt value to use for encryption
35
36
  attr_accessor :salt
36
37
 
37
38
  # Configuration options:
@@ -39,13 +40,14 @@ module PluginAWeek #:nodoc:
39
40
  def initialize(options = {})
40
41
  options = options.symbolize_keys
41
42
  options.assert_valid_keys(:salt)
42
- options.reverse_merge!(:salt => @@default_salt)
43
- @salt = options[:salt]
43
+ options.reverse_merge!(:salt => self.class.default_salt)
44
+
45
+ self.salt = options[:salt].to_s
44
46
 
45
47
  super()
46
48
  end
47
49
 
48
- # Decryption is not supported.
50
+ # Decryption is not supported
49
51
  def can_decrypt?
50
52
  false
51
53
  end
@@ -47,7 +47,10 @@ module PluginAWeek #:nodoc:
47
47
  @@default_key = nil
48
48
  cattr_accessor :default_key
49
49
 
50
+ # The algorithm to use for encryption/decryption
50
51
  attr_accessor :algorithm
52
+
53
+ # The private key that seeds the algorithm
51
54
  attr_accessor :key
52
55
 
53
56
  # Configuration options:
@@ -59,8 +62,8 @@ module PluginAWeek #:nodoc:
59
62
  :key,
60
63
  :algorithm
61
64
  )
62
- options.reverse_merge!(:key => @@default_key)
63
- options[:algorithm] ||= @@default_algorithm
65
+ options.reverse_merge!(:key => self.class.default_key)
66
+ options[:algorithm] ||= self.class.default_algorithm
64
67
 
65
68
  self.key = options[:key]
66
69
  raise NoKeyError if key.nil?
@@ -1,97 +1,165 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
- class AsymmetricEncryptorTest < Test::Unit::TestCase
3
+ class AsymmetricEncryptorByDefaultTest < Test::Unit::TestCase
4
4
  def setup
5
- @data = 'encrypted_strings'
6
- @key = 'secret'
7
- @public_key_file = File.dirname(__FILE__) + '/keys/public'
8
- @private_key_file = File.dirname(__FILE__) + '/keys/private'
9
- @encrypted_public_key_file = File.dirname(__FILE__) + '/keys/encrypted_public'
10
- @encrypted_private_key_file = File.dirname(__FILE__) + '/keys/encrypted_private'
11
-
12
- @encrypted_data = "NMGkkSu8dFdM455ru46b8TIkWQDHVdi4aJFZBCZ5p2VQV88OJnLBnnWYBXZk\n8HcyXzKb1I9lxuVHU/eZorGl7Q==\n"
13
- @encrypted_data_with_encrypted_keys = "C6sJrSzSaVZ9gCPanUpUmSir5At6tMfBzPvJO/MXYJVJNxF3uKMy9IsJHqos\nz5tVAdyOUNBr3jroqFK22mdKqw==\n"
5
+ PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_public_key_file = File.dirname(__FILE__) + '/keys/public'
6
+ PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_private_key_file = File.dirname(__FILE__) + '/keys/private'
7
+ PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_algorithm = 'DES-EDE3-CBC'
14
8
 
9
+ @asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new
10
+ end
11
+
12
+ def test_should_use_the_default_public_key_file
13
+ assert_equal File.dirname(__FILE__) + '/keys/public', @asymmetric_encryptor.public_key_file
14
+ end
15
+
16
+ def test_should_use_the_default_private_key_file
17
+ assert_equal File.dirname(__FILE__) + '/keys/private', @asymmetric_encryptor.private_key_file
18
+ end
19
+
20
+ def test_should_use_the_default_algorithm
21
+ assert_equal 'DES-EDE3-CBC', @asymmetric_encryptor.default_algorithm
22
+ end
23
+
24
+ def test_should_not_have_a_key
25
+ assert_nil @asymmetric_encryptor.key
26
+ end
27
+
28
+ def teardown
15
29
  PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_public_key_file = nil
16
30
  PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_private_key_file = nil
31
+ PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_algorithm = nil
32
+ end
33
+ end
34
+
35
+ class AsymmetricEncryptorWithInvalidOptionsTest < Test::Unit::TestCase
36
+ def test_should_throw_an_exception
37
+ assert_raise(ArgumentError) {PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:invalid => true)}
38
+ end
39
+ end
40
+
41
+ class AsymmetricEncryptorTest < Test::Unit::TestCase
42
+ def setup
43
+ @asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new
17
44
  end
18
45
 
19
- def test_should_not_be_public_without_public_key_file
20
- encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new
21
- assert !encryptor.public?
46
+ def test_should_be_able_to_decrypt
47
+ assert @asymmetric_encryptor.can_decrypt?
48
+ end
49
+ end
50
+
51
+ class AsymmetricEncryptorWithoutPublicKeyTest < Test::Unit::TestCase
52
+ def setup
53
+ @asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:public_key_file => nil)
22
54
  end
23
55
 
24
- def test_should_not_be_private_without_privae_key_file
25
- encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new
26
- assert !encryptor.private?
56
+ def test_should_not_be_public
57
+ assert !@asymmetric_encryptor.public?
27
58
  end
28
59
 
29
- def test_should_read_key_files
30
- encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(
31
- :public_key_file => @public_key_file,
32
- :private_key_file => @private_key_file
33
- )
34
- assert encryptor.public?
35
- assert encryptor.private?
60
+ def test_should_not_be_able_to_encrypt
61
+ assert_raise(PluginAWeek::EncryptedStrings::NoPublicKeyError) {@asymmetric_encryptor.encrypt('test')}
62
+ end
63
+ end
64
+
65
+ class AsymmetricEncryptorWithPublicKeyTest < Test::Unit::TestCase
66
+ def setup
67
+ @asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:public_key_file => File.dirname(__FILE__) + '/keys/public')
36
68
  end
37
69
 
38
- def test_should_read_encrypted_key_files
39
- encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(
40
- :public_key_file => @encrypted_public_key_file,
41
- :private_key_file => @encrypted_private_key_file
42
- )
43
- assert encryptor.public?
44
- assert encryptor.private?
70
+ def test_should_be_public
71
+ assert @asymmetric_encryptor.public?
45
72
  end
46
73
 
47
- def test_should_decrypt_files
48
- encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(
49
- :public_key_file => @public_key_file,
50
- :private_key_file => @private_key_file
51
- )
52
-
53
- assert_equal @data, encryptor.decrypt(@encrypted_data)
74
+ def test_should_not_be_private
75
+ assert !@asymmetric_encryptor.private?
54
76
  end
55
77
 
56
- def test_should_decrypt_files_with_encrypted_key
57
- encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(
58
- :public_key_file => @encrypted_public_key_file,
59
- :private_key_file => @encrypted_private_key_file,
60
- :key => @key
61
- )
62
-
63
- assert_equal @data, encryptor.decrypt(@encrypted_data_with_encrypted_keys)
78
+ def test_should_be_able_to_encrypt
79
+ assert_equal 90, @asymmetric_encryptor.encrypt('test').length
64
80
  end
65
81
 
66
- def test_should_decrypt_files_with_default_key
67
- set_default_key_files @public_key_file, @private_key_file
68
- assert_equal @data, PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new.decrypt(@encrypted_data)
82
+ def test_should_not_be_able_to_decrypt
83
+ assert_raise(PluginAWeek::EncryptedStrings::NoPrivateKeyError) {@asymmetric_encryptor.decrypt("HbEh0Hwri26S7SWYqO26DBbzfhR1h/0pXYLjSKUpxF5DOaOCtD9oRN748+Na\nrfNaVN5Eg7RUhbRFZE+UnNHo6Q==\n")}
84
+ end
85
+ end
86
+
87
+ class AsymmetricEncryptorWithoutPrivateKeyTest < Test::Unit::TestCase
88
+ def setup
89
+ @asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:private_key_file => nil)
69
90
  end
70
91
 
71
- def test_should_decrypt_files_with_default_encrypted_key
72
- set_default_key_files @encrypted_public_key_file, @encrypted_private_key_file
73
- assert_equal @data, PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:key => @key).decrypt(@encrypted_data_with_encrypted_keys)
92
+ def test_should_not_be_private
93
+ assert !@asymmetric_encryptor.private?
74
94
  end
75
95
 
76
- def test_should_read_key_files_with_default_key
77
- set_default_key_files @public_key_file, @private_key_file
78
-
79
- encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new
80
- assert encryptor.private?
81
- assert encryptor.public?
96
+ def test_should_not_be_able_to_decrypt
97
+ assert_raise(PluginAWeek::EncryptedStrings::NoPrivateKeyError) {@asymmetric_encryptor.decrypt("NMGkkSu8dFdM455ru46b8TIkWQDHVdi4aJFZBCZ5p2VQV88OJnLBnnWYBXZk\n8HcyXzKb1I9lxuVHU/eZorGl7Q==\n")}
98
+ end
99
+ end
100
+
101
+ class AsymmetricEncryptorWithPrivateKeyTest < Test::Unit::TestCase
102
+ def setup
103
+ @asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:private_key_file => File.dirname(__FILE__) + '/keys/private')
82
104
  end
83
105
 
84
- def test_should_read_encrypted_key_files_with_default_key
85
- set_default_key_files @encrypted_public_key_file, @encrypted_private_key_file
86
-
87
- encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new
88
- assert encryptor.private?
89
- assert encryptor.public?
106
+ def test_should_not_be_public
107
+ assert !@asymmetric_encryptor.public?
108
+ end
109
+
110
+ def test_should_be_private
111
+ assert @asymmetric_encryptor.private?
112
+ end
113
+
114
+ def test_not_should_be_able_to_encrypt
115
+ assert_raise(PluginAWeek::EncryptedStrings::NoPublicKeyError) {@asymmetric_encryptor.encrypt('test')}
116
+ end
117
+
118
+ def test_should_be_able_to_decrypt
119
+ assert_equal 'test', @asymmetric_encryptor.decrypt("HbEh0Hwri26S7SWYqO26DBbzfhR1h/0pXYLjSKUpxF5DOaOCtD9oRN748+Na\nrfNaVN5Eg7RUhbRFZE+UnNHo6Q==\n")
120
+ end
121
+ end
122
+
123
+ class AsymmetricEncryptorWithEncryptedPublicKeyTest < Test::Unit::TestCase
124
+ def setup
125
+ @asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:public_key_file => File.dirname(__FILE__) + '/keys/encrypted_public')
126
+ end
127
+
128
+ def test_should_be_public
129
+ assert @asymmetric_encryptor.public?
90
130
  end
91
131
 
92
- private
93
- def set_default_key_files(public_key, private_key)
94
- PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_public_key_file = public_key
95
- PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_private_key_file = private_key
96
- end
132
+ def test_should_not_be_private
133
+ assert !@asymmetric_encryptor.private?
134
+ end
135
+
136
+ def test_should_be_able_to_encrypt
137
+ assert_equal 90, @asymmetric_encryptor.encrypt('test').length
138
+ end
139
+
140
+ def test_should_not_be_able_to_decrypt
141
+ assert_raise(PluginAWeek::EncryptedStrings::NoPrivateKeyError) {@asymmetric_encryptor.decrypt("NMGkkSu8dFdM455ru46b8TIkWQDHVdi4aJFZBCZ5p2VQV88OJnLBnnWYBXZk\n8HcyXzKb1I9lxuVHU/eZorGl7Q==\n")}
142
+ end
143
+ end
144
+
145
+ class AsymmetricEncryptorWithEncryptedPrivateKeyTest < Test::Unit::TestCase
146
+ def setup
147
+ @asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:private_key_file => File.dirname(__FILE__) + '/keys/encrypted_private', :algorithm => 'DES-EDE3-CBC', :key => 'secret')
148
+ end
149
+
150
+ def test_should_not_be_public
151
+ assert !@asymmetric_encryptor.public?
152
+ end
153
+
154
+ def test_should_be_private
155
+ assert @asymmetric_encryptor.private?
156
+ end
157
+
158
+ def test_should_not_be_able_to_encrypt
159
+ assert_raise(PluginAWeek::EncryptedStrings::NoPublicKeyError) {@asymmetric_encryptor.encrypt('test')}
160
+ end
161
+
162
+ def test_should_be_able_to_decrypt
163
+ assert_equal 'test', @asymmetric_encryptor.decrypt("oo6gLdPuPGmiAD83EKMiXkod5jvoN4JC8azGbCF/ludwuik4QT58DAsidqsN\n5Xu103JgRIZjRgDEhNhO6szfAA==\n")
164
+ end
97
165
  end
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
- class EncryptorTest < Test::Unit::TestCase
3
+ class EncryptorByDefaultTest < Test::Unit::TestCase
4
4
  def setup
5
5
  @encryptor = PluginAWeek::EncryptedStrings::Encryptor.new
6
6
  end
@@ -1,16 +1,28 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
- class ShaEncryptorTest < Test::Unit::TestCase
3
+ class ShaEncryptorByDefaulTest < Test::Unit::TestCase
4
4
  def setup
5
- PluginAWeek::EncryptedStrings::ShaEncryptor.default_salt = 'salt'
5
+ @sha_encryptor = PluginAWeek::EncryptedStrings::ShaEncryptor.new
6
6
  end
7
7
 
8
- def test_should_encrypt_with_default_salt_if_salt_not_specified
9
- assert_equal 'f438229716cab43569496f3a3630b3727524b81b', PluginAWeek::EncryptedStrings::ShaEncryptor.new.encrypt('test')
8
+ def test_should_use_default_salt
9
+ assert_equal 'salt', @sha_encryptor.salt
10
10
  end
11
11
 
12
- def test_should_encrypt_with_custom_salt_if_salt_specified
13
- assert_equal '18e3256d71529db8fa65b2eef24a69ddad7070f3', PluginAWeek::EncryptedStrings::ShaEncryptor.new(:salt => 'different salt').encrypt('test')
12
+ def test_should_encrypt_using_default_salt
13
+ assert_equal 'f438229716cab43569496f3a3630b3727524b81b', @sha_encryptor.encrypt('test')
14
+ end
15
+ end
16
+
17
+ class ShaEncryptorWithInvalidOptionsTest < Test::Unit::TestCase
18
+ def test_should_throw_an_exception
19
+ assert_raise(ArgumentError) {PluginAWeek::EncryptedStrings::ShaEncryptor.new(:invalid => true)}
20
+ end
21
+ end
22
+
23
+ class ShaEncryptorTest < Test::Unit::TestCase
24
+ def setup
25
+ @sha_encryptor = PluginAWeek::EncryptedStrings::ShaEncryptor.new
14
26
  end
15
27
 
16
28
  def test_should_not_be_able_to_decrypt
@@ -21,3 +33,27 @@ class ShaEncryptorTest < Test::Unit::TestCase
21
33
  assert_raises(NotImplementedError) {PluginAWeek::EncryptedStrings::ShaEncryptor.new.decrypt('test')}
22
34
  end
23
35
  end
36
+
37
+ class ShaEncryptorWithCustomSaltTest < Test::Unit::TestCase
38
+ def setup
39
+ @sha_encryptor = PluginAWeek::EncryptedStrings::ShaEncryptor.new(:salt => 'different salt')
40
+ end
41
+
42
+ def test_should_use_custom_salt
43
+ assert_equal 'different salt', @sha_encryptor.salt
44
+ end
45
+
46
+ def test_should_encrypt_using_custom_salt
47
+ assert_equal '18e3256d71529db8fa65b2eef24a69ddad7070f3', @sha_encryptor.encrypt('test')
48
+ end
49
+ end
50
+
51
+ class ShaEncryptorWithNonStringSaltTest < Test::Unit::TestCase
52
+ def setup
53
+ @sha_encryptor = PluginAWeek::EncryptedStrings::ShaEncryptor.new(:salt => Time.parse('Tue Jan 01 00:00:00 UTC 2008'))
54
+ end
55
+
56
+ def test_should_stringify_salt
57
+ assert_equal 'Tue Jan 01 00:00:00 UTC 2008', @sha_encryptor.salt
58
+ end
59
+ end
data/test/string_test.rb CHANGED
@@ -1,105 +1,222 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
- class EncryptedStringsTest < Test::Unit::TestCase
4
- def test_should_use_sha_for_default_encryption
5
- assert_instance_of PluginAWeek::EncryptedStrings::ShaEncryptor, 'test'.encrypt.encryptor
3
+ class StringByDefaultTest < Test::Unit::TestCase
4
+ def setup
5
+ @encrypted_string = 'test'.encrypt
6
6
  end
7
7
 
8
- def test_should_use_configuration_options_for_default_encryption
9
- encrypted_string = 'test'.encrypt(:salt => 'different_salt')
10
- assert_instance_of PluginAWeek::EncryptedStrings::ShaEncryptor, encrypted_string.encryptor
11
- assert_equal 'different_salt', encrypted_string.encryptor.salt
8
+ def test_should_use_sha
9
+ assert_instance_of PluginAWeek::EncryptedStrings::ShaEncryptor, @encrypted_string.encryptor
10
+ end
11
+ end
12
+
13
+ class StringWithCustomOptionsTest < Test::Unit::TestCase
14
+ def setup
15
+ @encrypted_string = 'test'.encrypt(:salt => 'different_salt')
12
16
  end
13
17
 
14
- def test_should_use_custom_encryptor_if_mode_specified
15
- encrypted_string = 'test'.encrypt(:symmetric, :key => 'key')
16
- assert_instance_of PluginAWeek::EncryptedStrings::SymmetricEncryptor, encrypted_string.encryptor
18
+ def test_should_use_sha
19
+ assert_instance_of PluginAWeek::EncryptedStrings::ShaEncryptor, @encrypted_string.encryptor
17
20
  end
18
21
 
19
- def test_should_replace_string_with_bang_encryption
20
- encrypted_string = 'test'
21
- encrypted_string.encrypt!
22
-
23
- assert !'test'.equals_without_encryption(encrypted_string)
24
- assert_instance_of PluginAWeek::EncryptedStrings::ShaEncryptor, encrypted_string.encryptor
22
+ def test_should_use_custom_options
23
+ assert_equal 'different_salt', @encrypted_string.encryptor.salt
24
+ end
25
+ end
26
+
27
+ class StringWithCustomEncryptor
28
+ def setup
29
+ @encrypted_string = 'test'.encrypt(:symmetric, :key => 'key')
25
30
  end
26
31
 
27
- def test_should_be_encrypted_if_string_has_been_encrypted
28
- assert 'test'.encrypt.encrypted?
32
+ def test_should_use_custom_encryptor
33
+ assert_instance_of PluginAWeek::EncryptedStrings::SymmetricEncryptor, @encrypted_string.encryptor
34
+ end
35
+ end
36
+
37
+ class StringTest < Test::Unit::TestCase
38
+ def setup
39
+ @string = 'test'
29
40
  end
30
41
 
31
- def test_should_not_be_encrypted_if_string_has_not_been_encrypted
32
- assert !'test'.encrypted?
42
+ def test_should_not_be_encrypted
43
+ assert !@string.encrypted?
33
44
  end
34
45
 
35
- def test_should_not_be_encrypted_after_being_decrypted
36
- encrypted_string = 'test'.encrypt(:symmetric, :key => 'secret')
37
- decrypted_string = encrypted_string.decrypt
38
- assert !decrypted_string.encrypted?
46
+ def test_should_not_have_an_encryptor
47
+ assert_nil @string.encryptor
39
48
  end
40
49
 
41
- def test_should_use_encryptor_for_decryption_by_default
42
- encrypted_string = 'test'.encrypt(:symmetric, :key => 'secret')
43
- assert 'test'.equals_without_encryption(encrypted_string.decrypt)
50
+ def test_should_not_be_able_to_decrypt
51
+ assert !@string.can_decrypt?
52
+ end
53
+ end
54
+
55
+ class StringAfterBeingEncryptedTest < Test::Unit::TestCase
56
+ def setup
57
+ @encrypted_string = 'test'.encrypt
44
58
  end
45
59
 
46
- def test_should_allow_custom_mode_when_decrypting
47
- assert_equal 'test', "MU6e/5LvhKA=\n".decrypt(:symmetric, :key => 'secret')
60
+ def test_should_be_encrypted
61
+ assert @encrypted_string.encrypted?
62
+ end
63
+ end
64
+
65
+ class StringAfterBeingEncryptedAndReplacedTest < Test::Unit::TestCase
66
+ def setup
67
+ @encrypted_string = 'string'
68
+ @encrypted_string.encrypt!
48
69
  end
49
70
 
50
- def test_should_replace_string_with_bang_decryption
51
- encrypted_string = "MU6e/5LvhKA=\n"
52
- encrypted_string.decrypt!(:symmetric, :key => 'secret')
53
-
54
- assert !"MU6e/5LvhKA=\n".equals_without_encryption(encrypted_string)
55
- assert 'test'.equals_without_encryption(encrypted_string)
71
+ def test_should_not_be_the_original_value
72
+ assert !'test'.equals_without_encryption(@encrypted_string)
56
73
  end
57
74
 
58
- def test_should_be_able_to_decrypt_if_encryptor_can_decrypt
59
- assert 'test'.encrypt(:symmetric, :key => 'secret').can_decrypt?
75
+ def test_should_have_an_encryptor
76
+ assert_instance_of PluginAWeek::EncryptedStrings::ShaEncryptor, @encrypted_string.encryptor
60
77
  end
61
78
 
62
- def test_should_not_be_able_to_decrypt_if_encryptor_cant_decrypt
63
- assert !'test'.encrypt(:sha).can_decrypt?
79
+ def test_should_be_encrypted
80
+ assert @encrypted_string.encrypted?
81
+ end
82
+ end
83
+
84
+ class StringAfterBeingDecryptedTest < Test::Unit::TestCase
85
+ def setup
86
+ @encrypted_string = 'test'.encrypt(:symmetric, :key => 'secret')
87
+ @decrypted_string = @encrypted_string.decrypt
64
88
  end
65
89
 
66
- def test_should_not_be_able_to_decrypt_if_never_encrypted
67
- assert !'test'.can_decrypt?
90
+ def test_should_not_be_encrypted
91
+ assert !@decrypted_string.encrypted?
68
92
  end
69
93
 
70
- def test_should_be_able_to_check_equality_without_decryption_support
71
- value = 'test'
72
- encrypted_string = 'test'.encrypt(:sha)
73
- encrypted_encrypted_string = encrypted_string.encrypt(:sha)
74
-
75
- assert_equal value, encrypted_string
76
- assert_equal encrypted_string, value
77
- assert_equal encrypted_string, encrypted_encrypted_string
78
- assert_equal encrypted_encrypted_string, encrypted_string
79
- assert_equal encrypted_string.to_s, encrypted_string
80
- assert_equal encrypted_string, encrypted_string.to_s
81
- assert_equal encrypted_string, encrypted_string
94
+ def test_should_not_have_an_encryptor
95
+ assert_nil @decrypted_string.encryptor
96
+ end
97
+ end
98
+
99
+ class StringAfterBeingDecryptedAndReplacedTest < Test::Unit::TestCase
100
+ def setup
101
+ @encrypted_string = 'test'.encrypt(:symmetric, :key => 'secret')
102
+ @encrypted_string.decrypt!
103
+ end
104
+
105
+ def test_should_not_be_the_original_value
106
+ assert !"MU6e/5LvhKA=\n".equals_without_encryption(@encrypted_string)
107
+ end
108
+
109
+ def test_should_be_the_decrypted_value
110
+ assert 'test'.equals_without_encryption(@encrypted_string)
111
+ end
112
+
113
+ def test_should_not_have_an_encryptor
114
+ assert_nil @encrypted_string.encryptor
115
+ end
116
+
117
+ def test_should_not_be_encrypted
118
+ assert !@encrypted_string.encrypted?
119
+ end
120
+ end
121
+
122
+ class StringWithUndecryptableEncryptorTest < Test::Unit::TestCase
123
+ def setup
124
+ @encrypted_string = 'test'.encrypt(:sha)
125
+ end
126
+
127
+ def test_should_not_be_able_to_decrypt
128
+ assert !@encrypted_string.can_decrypt?
129
+ end
130
+
131
+ def test_should_raise_exception_if_decrypted
132
+ assert_raise(NotImplementedError) {@encrypted_string.decrypt}
133
+ end
134
+
135
+ def test_should_be_able_to_check_equality_with_itself
136
+ assert_equal @encrypted_string, @encrypted_string
137
+ end
138
+
139
+ def test_should_be_able_to_check_equality_with_unencrypted_string
140
+ assert_equal 'test', @encrypted_string
141
+ assert_equal @encrypted_string, 'test'
142
+ end
143
+
144
+ def test_should_be_able_to_check_equality_with_encrypted_value_of_encrypted_string
145
+ encrypted_encrypted_string = @encrypted_string.encrypt(:sha)
82
146
 
83
- assert_not_equal value, encrypted_encrypted_string
84
- assert_not_equal encrypted_encrypted_string, value
147
+ assert_equal @encrypted_string, encrypted_encrypted_string
148
+ assert_equal encrypted_encrypted_string, @encrypted_string
149
+ end
150
+
151
+ def test_should_be_able_to_check_equality_with_same_string_without_encryptor
152
+ assert_equal @encrypted_string.to_s, @encrypted_string
153
+ assert_equal @encrypted_string, @encrypted_string.to_s
85
154
  end
86
155
 
87
- def test_should_be_able_to_check_equality_with_decryption_support
88
- PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_key = 'secret'
156
+ def test_should_not_be_able_to_check_equality_more_than_one_encryption_away
157
+ encrypted_encrypted_string = @encrypted_string.encrypt(:sha)
89
158
 
90
- value = 'test'
91
- encrypted_string = value.encrypt(:symmetric)
92
- encrypted_encrypted_string = encrypted_string.encrypt(:symmetric)
159
+ assert_not_equal 'test', encrypted_encrypted_string
160
+ assert_not_equal encrypted_encrypted_string, 'test'
161
+ end
162
+ end
163
+
164
+ class StringWithDecryptableEncryptorTest < Test::Unit::TestCase
165
+ def setup
166
+ @encrypted_string = 'test'.encrypt(:symmetric, :key => 'secret')
167
+ end
168
+
169
+ def test_should_be_able_to_decrypt
170
+ assert @encrypted_string.can_decrypt?
171
+ end
172
+
173
+ def test_should_be_able_to_check_equality_with_itself
174
+ assert_equal @encrypted_string, @encrypted_string
175
+ end
176
+
177
+ def test_should_be_able_to_check_equality_with_unencrypted_string
178
+ assert_equal 'test', @encrypted_string
179
+ assert_equal @encrypted_string, 'test'
180
+ end
181
+
182
+ def test_should_be_able_to_check_equality_with_encrypted_value_of_encrypted_string
183
+ encrypted_encrypted_string = @encrypted_string.encrypt(:symmetric, :key => 'secret')
93
184
 
94
- assert_equal value, encrypted_string
95
- assert_equal encrypted_string, value
96
- assert_equal encrypted_string, encrypted_encrypted_string
97
- assert_equal encrypted_encrypted_string, encrypted_string
98
- assert_equal encrypted_string.to_s, encrypted_string
99
- assert_equal encrypted_string, encrypted_string.to_s
100
- assert_equal encrypted_string, encrypted_string
185
+ assert_equal @encrypted_string, encrypted_encrypted_string
186
+ assert_equal encrypted_encrypted_string, @encrypted_string
187
+ end
188
+
189
+ def test_should_be_able_to_check_equality_with_same_string_without_encryptor
190
+ assert_equal @encrypted_string.to_s, @encrypted_string
191
+ assert_equal @encrypted_string, @encrypted_string.to_s
192
+ end
193
+
194
+ def test_should_not_be_able_to_check_equality_more_than_one_encryption_away
195
+ encrypted_encrypted_string = @encrypted_string.encrypt(:symmetric, :key => 'secret')
101
196
 
102
- assert_not_equal value, encrypted_encrypted_string
103
- assert_not_equal encrypted_encrypted_string, value
197
+ assert_not_equal 'test', encrypted_encrypted_string
198
+ assert_not_equal encrypted_encrypted_string, 'test'
199
+ end
200
+ end
201
+
202
+ class StringPreviouslyEncryptedTest < Test::Unit::TestCase
203
+ def setup
204
+ @encrypted_string = "MU6e/5LvhKA=\n"
205
+ end
206
+
207
+ def test_should_not_be_encrypted
208
+ assert !@encrypted_string.encrypted?
209
+ end
210
+
211
+ def test_should_not_have_an_encryptor
212
+ assert_nil @encrypted_string.encryptor
213
+ end
214
+
215
+ def test_should_not_be_able_to_decrypt
216
+ assert !@encrypted_string.can_decrypt?
217
+ end
218
+
219
+ def test_should_be_able_to_decrypt_with_custom_mode
220
+ assert_equal 'test', @encrypted_string.decrypt(:symmetric, :key => 'secret')
104
221
  end
105
222
  end
@@ -1,36 +1,66 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
- class SymmetricallyEncryptedStringTest < Test::Unit::TestCase
3
+ class SymmetricEncryptorByDefaultTest < Test::Unit::TestCase
4
4
  def setup
5
- @data = 'test'
6
- @key = 'secret'
7
- @encrypted = "MU6e/5LvhKA=\n"
8
- PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_key = nil
5
+ PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_key = 'secret'
6
+ @symmetric_encryptor = PluginAWeek::EncryptedStrings::SymmetricEncryptor.new
7
+ end
8
+
9
+ def test_should_use_the_default_key
10
+ assert_equal 'secret', @symmetric_encryptor.key
9
11
  end
10
12
 
11
- def test_should_raise_exception_if_no_key_specified
12
- assert_raises(PluginAWeek::EncryptedStrings::NoKeyError) { PluginAWeek::EncryptedStrings::SymmetricEncryptor.new }
13
+ def test_should_use_the_default_algorithm
14
+ assert_equal 'DES-EDE3-CBC', @symmetric_encryptor.algorithm
13
15
  end
14
16
 
15
- def test_encrypt_with_default_key_if_key_not_specified
16
- PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_key = @key
17
- assert_equal @encrypted, PluginAWeek::EncryptedStrings::SymmetricEncryptor.new.encrypt(@data)
17
+ def test_should_encrypt_using_the_default_configuration
18
+ assert_equal "MU6e/5LvhKA=\n", @symmetric_encryptor.encrypt('test')
18
19
  end
19
20
 
20
- def test_should_encrypt_with_custom_key_if_key_specified
21
- assert_equal @encrypted, PluginAWeek::EncryptedStrings::SymmetricEncryptor.new(:key => @key).encrypt(@data)
21
+ def test_should_decrypt_encrypted_string_using_the_default_configuration
22
+ assert_equal 'test', @symmetric_encryptor.decrypt("MU6e/5LvhKA=\n")
23
+ end
24
+
25
+ def teardown
26
+ PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_key = nil
27
+ end
28
+ end
29
+
30
+ class SymmetricEncryptorWithInvalidOptionsTest < Test::Unit::TestCase
31
+ def test_should_throw_an_exception
32
+ assert_raise(ArgumentError) {PluginAWeek::EncryptedStrings::SymmetricEncryptor.new(:invalid => true)}
33
+ end
34
+ end
35
+
36
+ class SymmetricEncryptorTest < Test::Unit::TestCase
37
+ def setup
38
+ @symmetric_encryptor = PluginAWeek::EncryptedStrings::SymmetricEncryptor.new(:key => 'secret')
22
39
  end
23
40
 
24
41
  def test_should_be_able_to_decrypt
25
- assert PluginAWeek::EncryptedStrings::SymmetricEncryptor.new(:key => @key).can_decrypt?
42
+ assert @symmetric_encryptor.can_decrypt?
43
+ end
44
+ end
45
+
46
+ class SymmetricEncryptorWithCustomOptionsTest < Test::Unit::TestCase
47
+ def setup
48
+ @symmetric_encryptor = PluginAWeek::EncryptedStrings::SymmetricEncryptor.new(:key => 'secret', :algorithm => 'DES-EDE3-CFB')
49
+ end
50
+
51
+ def test_should_use_custom_key
52
+ assert_equal 'secret', @symmetric_encryptor.key
53
+ end
54
+
55
+ def test_should_use_custom_algorithm
56
+ assert_equal 'DES-EDE3-CFB', @symmetric_encryptor.algorithm
26
57
  end
27
58
 
28
- def test_should_decrypt_encrypted_string_with_custom_key_if_key_specified
29
- assert_equal @data, PluginAWeek::EncryptedStrings::SymmetricEncryptor.new(:key => @key).decrypt(@encrypted)
59
+ def test_should_encrypt_using_custom_options
60
+ assert_equal "C7D9mg==\n", @symmetric_encryptor.encrypt('test')
30
61
  end
31
62
 
32
- def test_should_decrypt_encrypted_string_with_default_key_if_key_not_specified
33
- PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_key = @key
34
- assert_equal @data, PluginAWeek::EncryptedStrings::SymmetricEncryptor.new.decrypt(@encrypted)
63
+ def test_should_decrypt_using_custom_options
64
+ assert_equal 'test', @symmetric_encryptor.decrypt("C7D9mg==\n")
35
65
  end
36
66
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: encrypted_strings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Pfeifer
8
- autorequire: encrypted_strings
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-05 00:00:00 -04:00
12
+ date: 2008-07-05 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -24,34 +24,34 @@ extra_rdoc_files: []
24
24
  files:
25
25
  - lib/encrypted_strings.rb
26
26
  - lib/encrypted_strings
27
- - lib/encrypted_strings/no_private_key_error.rb
28
27
  - lib/encrypted_strings/no_key_error.rb
28
+ - lib/encrypted_strings/encryptor.rb
29
+ - lib/encrypted_strings/symmetric_encryptor.rb
29
30
  - lib/encrypted_strings/no_public_key_error.rb
30
31
  - lib/encrypted_strings/asymmetric_encryptor.rb
31
- - lib/encrypted_strings/symmetric_encryptor.rb
32
32
  - lib/encrypted_strings/sha_encryptor.rb
33
- - lib/encrypted_strings/encryptor.rb
33
+ - lib/encrypted_strings/no_private_key_error.rb
34
34
  - lib/encrypted_strings/extensions
35
35
  - lib/encrypted_strings/extensions/string.rb
36
+ - test/symmetric_encryptor_test.rb
37
+ - test/no_public_key_error_test.rb
38
+ - test/sha_encryptor_test.rb
36
39
  - test/keys
37
- - test/keys/private
38
40
  - test/keys/encrypted_private
41
+ - test/keys/private
39
42
  - test/keys/public
40
43
  - test/keys/encrypted_public
41
- - test/no_private_key_error_test.rb
42
- - test/encryptor_test.rb
43
- - test/asymmetric_encryptor_test.rb
44
44
  - test/no_key_error_test.rb
45
- - test/sha_encryptor_test.rb
46
45
  - test/test_helper.rb
47
- - test/no_public_key_error_test.rb
48
46
  - test/string_test.rb
49
- - test/symmetric_encryptor_test.rb
50
- - CHANGELOG
47
+ - test/asymmetric_encryptor_test.rb
48
+ - test/encryptor_test.rb
49
+ - test/no_private_key_error_test.rb
50
+ - CHANGELOG.rdoc
51
51
  - init.rb
52
- - MIT-LICENSE
52
+ - LICENSE
53
53
  - Rakefile
54
- - README
54
+ - README.rdoc
55
55
  has_rdoc: true
56
56
  homepage: http://www.pluginaweek.org
57
57
  post_install_message:
@@ -73,17 +73,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  version:
74
74
  requirements: []
75
75
 
76
- rubyforge_project:
77
- rubygems_version: 1.1.0
76
+ rubyforge_project: pluginaweek
77
+ rubygems_version: 1.1.1
78
78
  signing_key:
79
79
  specification_version: 2
80
80
  summary: Dead-simple string encryption/decryption syntax.
81
81
  test_files:
82
- - test/no_private_key_error_test.rb
83
- - test/encryptor_test.rb
84
- - test/asymmetric_encryptor_test.rb
85
- - test/no_key_error_test.rb
86
- - test/sha_encryptor_test.rb
82
+ - test/symmetric_encryptor_test.rb
87
83
  - test/no_public_key_error_test.rb
84
+ - test/sha_encryptor_test.rb
85
+ - test/no_key_error_test.rb
88
86
  - test/string_test.rb
89
- - test/symmetric_encryptor_test.rb
87
+ - test/asymmetric_encryptor_test.rb
88
+ - test/encryptor_test.rb
89
+ - test/no_private_key_error_test.rb