encrypted_strings 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -0
- data/README.rdoc +2 -2
- data/Rakefile +1 -1
- data/lib/encrypted_strings/asymmetric_cipher.rb +162 -164
- data/lib/encrypted_strings/cipher.rb +14 -16
- data/lib/encrypted_strings/extensions/string.rb +186 -188
- data/lib/encrypted_strings/sha_cipher.rb +57 -59
- data/lib/encrypted_strings/symmetric_cipher.rb +91 -93
- data/test/asymmetric_cipher_test.rb +24 -24
- data/test/cipher_test.rb +1 -1
- data/test/sha_cipher_test.rb +11 -11
- data/test/string_test.rb +4 -4
- data/test/symmetric_cipher_test.rb +13 -13
- metadata +2 -2
data/test/cipher_test.rb
CHANGED
data/test/sha_cipher_test.rb
CHANGED
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/test_helper'
|
|
2
2
|
|
3
3
|
class ShaCipherByDefaulTest < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
@sha_cipher =
|
5
|
+
@sha_cipher = EncryptedStrings::ShaCipher.new
|
6
6
|
end
|
7
7
|
|
8
8
|
def test_should_use_default_salt
|
@@ -16,9 +16,9 @@ end
|
|
16
16
|
|
17
17
|
class ShaCipherWithCustomDefaultsTest < Test::Unit::TestCase
|
18
18
|
def setup
|
19
|
-
@original_default_salt =
|
20
|
-
|
21
|
-
@sha_cipher =
|
19
|
+
@original_default_salt = EncryptedStrings::ShaCipher.default_salt
|
20
|
+
EncryptedStrings::ShaCipher.default_salt = 'custom_salt'
|
21
|
+
@sha_cipher = EncryptedStrings::ShaCipher.new
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_should_use_custom_default_salt
|
@@ -30,33 +30,33 @@ class ShaCipherWithCustomDefaultsTest < Test::Unit::TestCase
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def teardown
|
33
|
-
|
33
|
+
EncryptedStrings::ShaCipher.default_salt = @original_default_salt
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
class ShaCipherWithInvalidOptionsTest < Test::Unit::TestCase
|
38
38
|
def test_should_throw_an_exception
|
39
|
-
assert_raise(ArgumentError) {
|
39
|
+
assert_raise(ArgumentError) {EncryptedStrings::ShaCipher.new(:invalid => true)}
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
class ShaCipherTest < Test::Unit::TestCase
|
44
44
|
def setup
|
45
|
-
@sha_cipher =
|
45
|
+
@sha_cipher = EncryptedStrings::ShaCipher.new
|
46
46
|
end
|
47
47
|
|
48
48
|
def test_should_not_be_able_to_decrypt
|
49
|
-
assert !
|
49
|
+
assert !EncryptedStrings::ShaCipher.new.can_decrypt?
|
50
50
|
end
|
51
51
|
|
52
52
|
def test_should_raise_exception_if_trying_to_decrypt
|
53
|
-
assert_raises(NotImplementedError) {
|
53
|
+
assert_raises(NotImplementedError) {EncryptedStrings::ShaCipher.new.decrypt('test')}
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
class ShaCipherWithCustomOptionsTest < Test::Unit::TestCase
|
58
58
|
def setup
|
59
|
-
@sha_cipher =
|
59
|
+
@sha_cipher = EncryptedStrings::ShaCipher.new(:salt => 'different salt')
|
60
60
|
end
|
61
61
|
|
62
62
|
def test_should_use_custom_salt
|
@@ -72,7 +72,7 @@ class ShaCipherWithNonStringSaltTest < Test::Unit::TestCase
|
|
72
72
|
require 'time'
|
73
73
|
|
74
74
|
def setup
|
75
|
-
@sha_cipher =
|
75
|
+
@sha_cipher = EncryptedStrings::ShaCipher.new(:salt => Time.parse('Tue Jan 01 00:00:00 UTC 2008'))
|
76
76
|
end
|
77
77
|
|
78
78
|
def test_should_stringify_salt
|
data/test/string_test.rb
CHANGED
@@ -6,7 +6,7 @@ class StringByDefaultTest < Test::Unit::TestCase
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def test_should_use_sha
|
9
|
-
assert_instance_of
|
9
|
+
assert_instance_of EncryptedStrings::ShaCipher, @encrypted_string.cipher
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -16,7 +16,7 @@ class StringWithCustomOptionsTest < Test::Unit::TestCase
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_should_use_sha
|
19
|
-
assert_instance_of
|
19
|
+
assert_instance_of EncryptedStrings::ShaCipher, @encrypted_string.cipher
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_should_use_custom_options
|
@@ -30,7 +30,7 @@ class StringWithCustomCipher
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_should_use_custom_cipher
|
33
|
-
assert_instance_of
|
33
|
+
assert_instance_of EncryptedStrings::SymmetricCipher, @encrypted_string.cipher
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -73,7 +73,7 @@ class StringAfterBeingEncryptedAndReplacedTest < Test::Unit::TestCase
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def test_should_have_a_cipher
|
76
|
-
assert_instance_of
|
76
|
+
assert_instance_of EncryptedStrings::ShaCipher, @encrypted_string.cipher
|
77
77
|
end
|
78
78
|
|
79
79
|
def test_should_be_encrypted
|
@@ -2,13 +2,13 @@ require File.dirname(__FILE__) + '/test_helper'
|
|
2
2
|
|
3
3
|
class NoPasswordErrorTest < Test::Unit::TestCase
|
4
4
|
def test_should_exist
|
5
|
-
assert_not_nil
|
5
|
+
assert_not_nil EncryptedStrings::NoPasswordError
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
9
|
class SymmetricCipherByDefaultTest < Test::Unit::TestCase
|
10
10
|
def setup
|
11
|
-
@symmetric_cipher =
|
11
|
+
@symmetric_cipher = EncryptedStrings::SymmetricCipher.new(:password => 'secret')
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_should_use_default_algorithm
|
@@ -16,7 +16,7 @@ class SymmetricCipherByDefaultTest < Test::Unit::TestCase
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_should_raise_exception
|
19
|
-
assert_raise(
|
19
|
+
assert_raise(EncryptedStrings::NoPasswordError) {EncryptedStrings::SymmetricCipher.new}
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_should_encrypt_using_default_configuration
|
@@ -30,12 +30,12 @@ end
|
|
30
30
|
|
31
31
|
class SymmetricCipherWithCustomDefaultsTest < Test::Unit::TestCase
|
32
32
|
def setup
|
33
|
-
@original_default_algorithm =
|
34
|
-
@original_default_password =
|
33
|
+
@original_default_algorithm = EncryptedStrings::SymmetricCipher.default_algorithm
|
34
|
+
@original_default_password = EncryptedStrings::SymmetricCipher.default_password
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
@symmetric_cipher =
|
36
|
+
EncryptedStrings::SymmetricCipher.default_algorithm = 'DES-EDE3-CFB'
|
37
|
+
EncryptedStrings::SymmetricCipher.default_password = 'secret'
|
38
|
+
@symmetric_cipher = EncryptedStrings::SymmetricCipher.new
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_should_use_custom_default_algorithm
|
@@ -55,20 +55,20 @@ class SymmetricCipherWithCustomDefaultsTest < Test::Unit::TestCase
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def teardown
|
58
|
-
|
59
|
-
|
58
|
+
EncryptedStrings::SymmetricCipher.default_algorithm = @original_default_algorithm
|
59
|
+
EncryptedStrings::SymmetricCipher.default_password = @original_default_password
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
class SymmetricCipherWithInvalidOptionsTest < Test::Unit::TestCase
|
64
64
|
def test_should_throw_an_exception
|
65
|
-
assert_raise(ArgumentError) {
|
65
|
+
assert_raise(ArgumentError) {EncryptedStrings::SymmetricCipher.new(:invalid => true)}
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
69
|
class SymmetricCipherTest < Test::Unit::TestCase
|
70
70
|
def setup
|
71
|
-
@symmetric_cipher =
|
71
|
+
@symmetric_cipher = EncryptedStrings::SymmetricCipher.new(:password => 'secret')
|
72
72
|
end
|
73
73
|
|
74
74
|
def test_should_be_able_to_decrypt
|
@@ -78,7 +78,7 @@ end
|
|
78
78
|
|
79
79
|
class SymmetricCipherWithCustomOptionsTest < Test::Unit::TestCase
|
80
80
|
def setup
|
81
|
-
@symmetric_cipher =
|
81
|
+
@symmetric_cipher = EncryptedStrings::SymmetricCipher.new(:algorithm => 'DES-EDE3-CFB', :password => 'secret')
|
82
82
|
end
|
83
83
|
|
84
84
|
def test_should_use_custom_algorithm
|
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.
|
4
|
+
version: 0.3.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-12-
|
12
|
+
date: 2008-12-14 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|