Skip to content

Commit e36e8d0

Browse files
committed
remove trailing whitespace
1 parent 196ce64 commit e36e8d0

3 files changed

Lines changed: 42 additions & 42 deletions

File tree

encrypted_strings.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
1414
s.test_files = `git ls-files -- test/*`.split("\n")
1515
s.rdoc_options = %w(--line-numbers --inline-source --title encrypted_strings --main README.rdoc)
1616
s.extra_rdoc_files = %w(README.rdoc CHANGELOG.rdoc LICENSE)
17-
17+
1818
s.add_development_dependency("maxitest")
1919
s.add_development_dependency("rake")
2020
end

lib/encrypted_strings/symmetric_cipher.rb

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,95 +2,95 @@ module EncryptedStrings
22
# Indicates no password was specified for the symmetric cipher
33
class NoPasswordError < StandardError
44
end
5-
5+
66
# Symmetric encryption uses a specific algorithm and password to encrypt
77
# the string. As long as the algorithm and password are known, the string
88
# can be decrypted.
9-
#
9+
#
1010
# Source: http://support.microsoft.com/kb/246071
11-
#
12-
# == Encrypting
13-
#
11+
#
12+
# == Encrypting
13+
#
1414
# To encrypt a string using a symmetric cipher, the algorithm and password
1515
# must be specified. You can define the defaults for these values like so:
16-
#
16+
#
1717
# EncryptedStrings::SymmetricCipher.default_algorithm = 'des-ecb'
1818
# EncryptedStrings::SymmetricCipher.default_password = 'secret'
19-
#
19+
#
2020
# If these configuration options are not passed in to #encrypt, then the
2121
# default values will be used. You can override the default values like so:
22-
#
22+
#
2323
# password = 'shhhh'
2424
# password.encrypt(:symmetric, :algorithm => 'des-ecb', :password => 'secret') # => "S/sEkViX3v4=\n"
25-
#
25+
#
2626
# An exception will be raised if no password is specified.
27-
#
27+
#
2828
# == Decrypting
29-
#
29+
#
3030
# To decrypt a string using an symmetric cipher, the algorithm and password
3131
# must be specified. Defaults for these values can be defined as show above.
32-
#
32+
#
3333
# If these configuration options are not passed in to #decrypt, then the
3434
# default values will be used. You can override the default values like so:
35-
#
35+
#
3636
# password = "S/sEkViX3v4=\n"
3737
# password.decrypt(:symmetric, :algorithm => 'des-ecb', :password => 'secret') # => "shhhh"
38-
#
38+
#
3939
# An exception will be raised if no password is specified.
4040
class SymmetricCipher < Cipher
4141
class << self
4242
# The default algorithm to use for encryption. Default is DES-EDE3-CBC.
4343
attr_accessor :default_algorithm
44-
44+
4545
# The default password to use for generating the key and initialization
4646
# vector. Default is nil.
4747
attr_accessor :default_password
4848
end
49-
49+
5050
# Set default values
5151
@default_algorithm = 'DES-EDE3-CBC'
52-
52+
5353
# The algorithm to use for encryption/decryption
5454
attr_accessor :algorithm
55-
55+
5656
# The password that generates the key/initialization vector for the
5757
# algorithm
5858
attr_accessor :password
59-
59+
6060
# Creates a new cipher that uses a symmetric encryption strategy.
61-
#
61+
#
6262
# Configuration options:
6363
# * <tt>:algorithm</tt> - The algorithm to use for generating the encrypted string
6464
# * <tt>:password</tt> - The secret value to use for generating the
6565
# key/initialization vector for the algorithm
6666
def initialize(options = {})
6767
invalid_options = options.keys - [:algorithm, :password]
6868
raise ArgumentError, "Unknown key(s): #{invalid_options.join(", ")}" unless invalid_options.empty?
69-
69+
7070
options = {
7171
:algorithm => SymmetricCipher.default_algorithm,
7272
:password => SymmetricCipher.default_password
7373
}.merge(options)
74-
74+
7575
self.algorithm = options[:algorithm]
7676
self.password = options[:password]
7777
raise NoPasswordError if password.nil?
78-
78+
7979
super()
8080
end
81-
81+
8282
# Decrypts the current string using the current key and algorithm specified
8383
def decrypt(data)
8484
cipher = build_cipher(:decrypt)
8585
cipher.update(data.unpack('m')[0]) + cipher.final
8686
end
87-
87+
8888
# Encrypts the current string using the current key and algorithm specified
8989
def encrypt(data)
9090
cipher = build_cipher(:encrypt)
9191
[cipher.update(data) + cipher.final].pack('m')
9292
end
93-
93+
9494
private
9595
def build_cipher(type) #:nodoc:
9696
cipher = OpenSSL::Cipher::Cipher.new(algorithm).send(type)

test/symmetric_cipher_test.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ class SymmetricCipherByDefaultTest < Minitest::Test
1010
def setup
1111
@symmetric_cipher = EncryptedStrings::SymmetricCipher.new(:password => 'secret')
1212
end
13-
13+
1414
def test_should_use_default_algorithm
1515
assert_equal 'DES-EDE3-CBC', @symmetric_cipher.algorithm
1616
end
17-
17+
1818
def test_should_raise_exception
1919
assert_raises(EncryptedStrings::NoPasswordError) {EncryptedStrings::SymmetricCipher.new}
2020
end
21-
21+
2222
def test_should_encrypt_using_default_configuration
2323
assert_equal "oTxJd67ElLY=\n", @symmetric_cipher.encrypt('test')
2424
end
25-
25+
2626
def test_should_decrypt_encrypted_string_using_default_configuration
2727
assert_equal 'test', @symmetric_cipher.decrypt("oTxJd67ElLY=\n")
2828
end
@@ -32,28 +32,28 @@ class SymmetricCipherWithCustomDefaultsTest < Minitest::Test
3232
def setup
3333
@original_default_algorithm = EncryptedStrings::SymmetricCipher.default_algorithm
3434
@original_default_password = EncryptedStrings::SymmetricCipher.default_password
35-
35+
3636
EncryptedStrings::SymmetricCipher.default_algorithm = 'DES-EDE3-CFB'
3737
EncryptedStrings::SymmetricCipher.default_password = 'secret'
3838
@symmetric_cipher = EncryptedStrings::SymmetricCipher.new
3939
end
40-
40+
4141
def test_should_use_custom_default_algorithm
4242
assert_equal 'DES-EDE3-CFB', @symmetric_cipher.algorithm
4343
end
44-
44+
4545
def test_should_use_custom_default_password
4646
assert_equal 'secret', @symmetric_cipher.password
4747
end
48-
48+
4949
def test_should_encrypt_using_custom_default_configuration
5050
assert_equal "QWz/eQ==\n", @symmetric_cipher.encrypt('test')
5151
end
52-
52+
5353
def test_should_decrypt_encrypted_string_using_custom_default_configuration
5454
assert_equal 'test', @symmetric_cipher.decrypt("QWz/eQ==\n")
5555
end
56-
56+
5757
def teardown
5858
EncryptedStrings::SymmetricCipher.default_algorithm = @original_default_algorithm
5959
EncryptedStrings::SymmetricCipher.default_password = @original_default_password
@@ -70,7 +70,7 @@ class SymmetricCipherTest < Minitest::Test
7070
def setup
7171
@symmetric_cipher = EncryptedStrings::SymmetricCipher.new(:password => 'secret')
7272
end
73-
73+
7474
def test_should_be_able_to_decrypt
7575
assert @symmetric_cipher.can_decrypt?
7676
end
@@ -80,19 +80,19 @@ class SymmetricCipherWithCustomOptionsTest < Minitest::Test
8080
def setup
8181
@symmetric_cipher = EncryptedStrings::SymmetricCipher.new(:algorithm => 'DES-EDE3-CFB', :password => 'secret')
8282
end
83-
83+
8484
def test_should_use_custom_algorithm
8585
assert_equal 'DES-EDE3-CFB', @symmetric_cipher.algorithm
8686
end
87-
87+
8888
def test_should_use_custom_password
8989
assert_equal 'secret', @symmetric_cipher.password
9090
end
91-
91+
9292
def test_should_encrypt_using_custom_options
9393
assert_equal "QWz/eQ==\n", @symmetric_cipher.encrypt('test')
9494
end
95-
95+
9696
def test_should_decrypt_using_custom_options
9797
assert_equal 'test', @symmetric_cipher.decrypt("QWz/eQ==\n")
9898
end

0 commit comments

Comments
 (0)