From 953592a29e9f9cebe1f09ffa89bd16e1887573be Mon Sep 17 00:00:00 2001 From: Yusuke Nakamura Date: Wed, 23 Nov 2022 21:05:49 +0900 Subject: [PATCH] Allow empty string to OpenSSL::Cipher#update For some reasons, plaintext may be empty string. ref https://www.rfc-editor.org/rfc/rfc9001.html#section-5.8 --- ext/openssl/ossl_cipher.c | 3 +-- test/openssl/test_cipher.rb | 6 ------ 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/ext/openssl/ossl_cipher.c b/ext/openssl/ossl_cipher.c index d9c789143..cb8fbc3ca 100644 --- a/ext/openssl/ossl_cipher.c +++ b/ext/openssl/ossl_cipher.c @@ -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) { diff --git a/test/openssl/test_cipher.rb b/test/openssl/test_cipher.rb index b5fdf0b3d..1c8610b2a 100644 --- a/test/openssl/test_cipher.rb +++ b/test/openssl/test_cipher.rb @@ -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") }