Skip to content

Commit

Permalink
Merge pull request #568 from unasuke/empty_string_to_cipher_update
Browse files Browse the repository at this point in the history
Allow empty string to OpenSSL::Cipher#update
  • Loading branch information
rhenium authored Nov 23, 2022
2 parents 1b419b9 + 953592a commit c1639f1
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 8 deletions.
3 changes: 1 addition & 2 deletions ext/openssl/ossl_cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,7 @@ ossl_cipher_update(int argc, VALUE *argv, VALUE self)

StringValue(data);
in = (unsigned char *)RSTRING_PTR(data);
if ((in_len = RSTRING_LEN(data)) == 0)
ossl_raise(rb_eArgError, "data must not be empty");
in_len = RSTRING_LEN(data);
GetCipher(self, ctx);
out_len = in_len+EVP_CIPHER_CTX_block_size(ctx);
if (out_len <= 0) {
Expand Down
6 changes: 0 additions & 6 deletions test/openssl/test_cipher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ def test_random_key_iv
assert_not_equal s1, s2
end

def test_empty_data
cipher = OpenSSL::Cipher.new("DES-EDE3-CBC").encrypt
cipher.random_key
assert_raise(ArgumentError) { cipher.update("") }
end

def test_initialize
cipher = OpenSSL::Cipher.new("DES-EDE3-CBC")
assert_raise(RuntimeError) { cipher.__send__(:initialize, "DES-EDE3-CBC") }
Expand Down

0 comments on commit c1639f1

Please sign in to comment.