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.
- data/{CHANGELOG → CHANGELOG.rdoc} +10 -8
- data/{MIT-LICENSE → LICENSE} +0 -0
- data/{README → README.rdoc} +7 -7
- data/Rakefile +48 -39
- data/lib/encrypted_strings/asymmetric_encryptor.rb +25 -14
- data/lib/encrypted_strings/encryptor.rb +3 -2
- data/lib/encrypted_strings/extensions/string.rb +3 -1
- data/lib/encrypted_strings/sha_encryptor.rb +5 -3
- data/lib/encrypted_strings/symmetric_encryptor.rb +5 -2
- data/test/asymmetric_encryptor_test.rb +136 -68
- data/test/encryptor_test.rb +1 -1
- data/test/sha_encryptor_test.rb +42 -6
- data/test/string_test.rb +186 -69
- data/test/symmetric_encryptor_test.rb +48 -18
- metadata +24 -24
@@ -1,23 +1,25 @@
|
|
1
|
-
|
1
|
+
== master
|
2
2
|
|
3
|
-
|
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
|
-
|
12
|
+
== 0.0.3 / 2007-09-18
|
8
13
|
|
9
14
|
* Remove gem dependency on activesupport
|
10
15
|
|
11
|
-
|
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
|
-
|
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
|
data/{MIT-LICENSE → LICENSE}
RENAMED
File without changes
|
data/{README → README.rdoc}
RENAMED
@@ -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://
|
17
|
+
* http://github.com/pluginaweek/encrypted_strings
|
18
18
|
|
19
19
|
Source
|
20
20
|
|
21
|
-
*
|
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://
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
26
|
+
desc "Test the #{spec.name} plugin."
|
15
27
|
Rake::TestTask.new(:test) do |t|
|
16
28
|
t.libs << 'lib'
|
17
|
-
t.
|
29
|
+
t.test_files = spec.test_files
|
18
30
|
t.verbose = true
|
19
31
|
end
|
20
32
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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', "#{
|
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/#{
|
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(
|
74
|
-
file = "pkg/#{
|
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(
|
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 => "./
|
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
|
-
|
65
|
-
attr_reader
|
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 =>
|
84
|
-
:public_key_file =>
|
85
|
-
: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
|
-
#
|
133
|
+
# Does this encryptor have a public key available?
|
125
134
|
def public?
|
126
|
-
return true
|
135
|
+
return true if @public_key
|
127
136
|
|
128
137
|
load_public_key
|
129
138
|
!@public_key.nil?
|
130
139
|
end
|
131
140
|
|
132
|
-
#
|
141
|
+
# Does this encryptor have a private key available?
|
133
142
|
def private?
|
134
|
-
return true
|
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
|
4
|
-
#
|
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 =>
|
43
|
-
|
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 =>
|
63
|
-
options[: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
|
3
|
+
class AsymmetricEncryptorByDefaultTest < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
20
|
-
|
21
|
-
|
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
|
25
|
-
|
26
|
-
assert !encryptor.private?
|
56
|
+
def test_should_not_be_public
|
57
|
+
assert !@asymmetric_encryptor.public?
|
27
58
|
end
|
28
59
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
39
|
-
|
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
|
48
|
-
|
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
|
57
|
-
|
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
|
67
|
-
|
68
|
-
|
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
|
72
|
-
|
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
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
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
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
assert
|
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
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
data/test/encryptor_test.rb
CHANGED
data/test/sha_encryptor_test.rb
CHANGED
@@ -1,16 +1,28 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class ShaEncryptorByDefaulTest < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
PluginAWeek::EncryptedStrings::ShaEncryptor.
|
5
|
+
@sha_encryptor = PluginAWeek::EncryptedStrings::ShaEncryptor.new
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
9
|
-
assert_equal '
|
8
|
+
def test_should_use_default_salt
|
9
|
+
assert_equal 'salt', @sha_encryptor.salt
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
assert_equal '
|
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
|
4
|
-
def
|
5
|
-
|
3
|
+
class StringByDefaultTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@encrypted_string = 'test'.encrypt
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
15
|
-
|
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
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
28
|
-
|
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
|
32
|
-
assert
|
42
|
+
def test_should_not_be_encrypted
|
43
|
+
assert !@string.encrypted?
|
33
44
|
end
|
34
45
|
|
35
|
-
def
|
36
|
-
|
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
|
42
|
-
|
43
|
-
|
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
|
47
|
-
|
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
|
51
|
-
encrypted_string
|
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
|
59
|
-
|
75
|
+
def test_should_have_an_encryptor
|
76
|
+
assert_instance_of PluginAWeek::EncryptedStrings::ShaEncryptor, @encrypted_string.encryptor
|
60
77
|
end
|
61
78
|
|
62
|
-
def
|
63
|
-
assert
|
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
|
67
|
-
assert
|
90
|
+
def test_should_not_be_encrypted
|
91
|
+
assert !@decrypted_string.encrypted?
|
68
92
|
end
|
69
93
|
|
70
|
-
def
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
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
|
-
|
84
|
-
|
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
|
88
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
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
|
95
|
-
assert_equal
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
assert_equal encrypted_string, encrypted_string
|
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
|
103
|
-
assert_not_equal encrypted_encrypted_string,
|
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
|
3
|
+
class SymmetricEncryptorByDefaultTest < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
|
6
|
-
@
|
7
|
-
|
8
|
-
|
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
|
12
|
-
|
13
|
+
def test_should_use_the_default_algorithm
|
14
|
+
assert_equal 'DES-EDE3-CBC', @symmetric_encryptor.algorithm
|
13
15
|
end
|
14
16
|
|
15
|
-
def
|
16
|
-
|
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
|
21
|
-
assert_equal
|
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
|
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
|
29
|
-
assert_equal
|
59
|
+
def test_should_encrypt_using_custom_options
|
60
|
+
assert_equal "C7D9mg==\n", @symmetric_encryptor.encrypt('test')
|
30
61
|
end
|
31
62
|
|
32
|
-
def
|
33
|
-
|
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
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Pfeifer
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
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/
|
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/
|
50
|
-
-
|
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
|
-
-
|
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.
|
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/
|
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/
|
87
|
+
- test/asymmetric_encryptor_test.rb
|
88
|
+
- test/encryptor_test.rb
|
89
|
+
- test/no_private_key_error_test.rb
|