encryptor 1.1.2 → 1.1.3

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.
@@ -27,8 +27,8 @@ module Encryptor
27
27
  # encrypted_value = Encryptor.encrypt(:value => 'some string to encrypt', :key => 'some secret key')
28
28
  # # or
29
29
  # encrypted_value = Encryptor.encrypt('some string to encrypt', :key => 'some secret key')
30
- def encrypt(*args)
31
- crypt :encrypt, *args
30
+ def encrypt(*args, &block)
31
+ crypt :encrypt, *args, &block
32
32
  end
33
33
 
34
34
  # Decrypts a <tt>:value</tt> with a specified <tt>:key</tt>
@@ -40,14 +40,15 @@ module Encryptor
40
40
  # decrypted_value = Encryptor.decrypt(:value => 'some encrypted string', :key => 'some secret key')
41
41
  # # or
42
42
  # decrypted_value = Encryptor.decrypt('some encrypted string', :key => 'some secret key')
43
- def decrypt(*args)
44
- crypt :decrypt, *args
43
+ def decrypt(*args, &block)
44
+ crypt :decrypt, *args, &block
45
45
  end
46
46
 
47
47
  protected
48
48
 
49
49
  def crypt(cipher_method, *args) #:nodoc:
50
50
  options = default_options.merge(:value => args.first).merge(args.last.is_a?(Hash) ? args.last : {})
51
+ raise ArgumentError.new('must specify a :key') if options[:key].to_s.empty?
51
52
  cipher = OpenSSL::Cipher::Cipher.new(options[:algorithm])
52
53
  cipher.send(cipher_method)
53
54
  if options[:iv]
@@ -56,6 +57,7 @@ module Encryptor
56
57
  else
57
58
  cipher.pkcs5_keyivgen(options[:key])
58
59
  end
60
+ yield cipher, options if block_given?
59
61
  result = cipher.update(options[:value])
60
62
  result << cipher.final
61
63
  end
@@ -3,7 +3,7 @@ module Encryptor
3
3
  module Version
4
4
  MAJOR = 1
5
5
  MINOR = 1
6
- PATCH = 2
6
+ PATCH = 3
7
7
 
8
8
  # Returns a version string by joining <tt>MAJOR</tt>, <tt>MINOR</tt>, and <tt>PATCH</tt> with <tt>'.'</tt>
9
9
  #
@@ -88,4 +88,17 @@ class EncryptorTest < Test::Unit::TestCase
88
88
  assert !Encryptor.default_options[:algorithm].empty?
89
89
  end
90
90
 
91
+ def test_should_raise_argument_error_if_key_is_not_specified
92
+ assert_raises(ArgumentError) { Encryptor.encrypt('some value') }
93
+ assert_raises(ArgumentError) { Encryptor.decrypt('some encrypted string') }
94
+ assert_raises(ArgumentError) { Encryptor.encrypt('some value', :key => '') }
95
+ assert_raises(ArgumentError) { Encryptor.decrypt('some encrypted string', :key => '') }
96
+ end
97
+
98
+ def test_should_yield_block_with_cipher_and_options
99
+ called = false
100
+ Encryptor.encrypt('some value', :key => 'some key') { |cipher, options| called = true }
101
+ assert called
102
+ end
103
+
91
104
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: encryptor
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 2
10
- version: 1.1.2
9
+ - 3
10
+ version: 1.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sean Huber
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-02 00:00:00 -07:00
18
+ date: 2011-04-12 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -41,11 +41,8 @@ homepage: http://github.com/shuber/encryptor
41
41
  licenses: []
42
42
 
43
43
  post_install_message:
44
- rdoc_options:
45
- - --line-numbers
46
- - --inline-source
47
- - --main
48
- - README.rdoc
44
+ rdoc_options: []
45
+
49
46
  require_paths:
50
47
  - lib
51
48
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -69,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
66
  requirements: []
70
67
 
71
68
  rubyforge_project:
72
- rubygems_version: 1.5.0
69
+ rubygems_version: 1.6.2
73
70
  signing_key:
74
71
  specification_version: 3
75
72
  summary: A simple wrapper for the standard ruby OpenSSL library