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 +4 -0
- data/Rakefile +1 -1
- data/lib/encrypted_strings/asymmetric_encryptor.rb +14 -18
- data/lib/encrypted_strings/extensions/string.rb +2 -2
- data/lib/encrypted_strings/sha_encryptor.rb +6 -5
- data/lib/encrypted_strings/symmetric_encryptor.rb +11 -11
- data/test/asymmetric_encryptor_test.rb +1 -1
- data/test/sha_encryptor_test.rb +2 -0
- data/test/test_helper.rb +0 -2
- metadata +2 -2
data/CHANGELOG.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -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
|
-
|
54
|
-
|
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
|
-
|
58
|
-
|
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
|
-
|
62
|
-
|
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
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
:
|
87
|
-
:
|
88
|
-
|
89
|
-
|
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).
|
192
|
-
|
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
|
-
|
33
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
44
|
-
|
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
|
-
|
48
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
options
|
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.
|
21
|
+
assert_equal 'DES-EDE3-CBC', @asymmetric_encryptor.algorithm
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_should_not_have_a_key
|
data/test/sha_encryptor_test.rb
CHANGED
@@ -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
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
|
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-
|
12
|
+
date: 2008-07-07 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|