Skip to content

Commit

Permalink
* ext/openssl/ossl_cipher.c (ossl_cipher_update): input data must
Browse files Browse the repository at this point in the history
  not be empty. [ruby-talk:161220]

* test/openssl/test_cipher.rb: add test for Cipher#update("").


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9485 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
gotoyuzo committed Oct 30, 2005
1 parent c53ecd2 commit 2c1d99d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ext/openssl/ossl_cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ ossl_cipher_update(VALUE self, VALUE data)

StringValue(data);
in = RSTRING(data)->ptr;
in_len = RSTRING(data)->len;
if ((in_len = RSTRING(data)->len) == 0)
rb_raise(rb_eArgError, "data must not be empty");
GetCipher(self, ctx);
str = rb_str_new(0, in_len+EVP_CIPHER_CTX_block_size(ctx));
if (!EVP_CipherUpdate(ctx, RSTRING(str)->ptr, &out_len, in, in_len))
Expand Down
5 changes: 5 additions & 0 deletions test/test_cipher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def test_reset
s2 = @c1.update(@data) + @c1.final
assert_equal(s1, s2, "encrypt reset")
end

def test_empty_data
@c1.encrypt
assert_raises(ArgumentError){ @c1.update("") }
end
end

end

0 comments on commit 2c1d99d

Please sign in to comment.