@@ -26,15 +26,15 @@ def test_openssl_engine_by_id_string
2626 with_openssl <<-'end;'
2727 orig = OpenSSL::Engine.engines
2828 pend "'openssl' is already loaded" if orig.any? { |e| e.id == "openssl" }
29- engine = get_engine
29+ engine = OpenSSL::Engine.by_id("openssl")
3030 assert_not_nil(engine)
3131 assert_equal(1, OpenSSL::Engine.engines.size - orig.size)
3232 end;
3333 end
3434
3535 def test_openssl_engine_id_name_inspect
3636 with_openssl <<-'end;'
37- engine = get_engine
37+ engine = OpenSSL::Engine.by_id("openssl")
3838 assert_equal("openssl", engine.id)
3939 assert_not_nil(engine.name)
4040 assert_not_nil(engine.inspect)
@@ -43,7 +43,7 @@ def test_openssl_engine_id_name_inspect
4343
4444 def test_openssl_engine_digest_sha1
4545 with_openssl <<-'end;'
46- engine = get_engine
46+ engine = OpenSSL::Engine.by_id("openssl")
4747 digest = engine.digest("SHA1")
4848 assert_not_nil(digest)
4949 data = "test"
@@ -59,12 +59,21 @@ def test_openssl_engine_cipher_rc4
5959 end
6060
6161 with_openssl ( <<-'end;' , ignore_stderr : true )
62- engine = get_engine
62+ engine = OpenSSL::Engine.by_id("openssl")
6363 algo = "RC4"
6464 data = "a" * 1000
6565 key = OpenSSL::Random.random_bytes(16)
66- encrypted = crypt_data(data, key, :encrypt) { engine.cipher(algo) }
67- decrypted = crypt_data(encrypted, key, :decrypt) { OpenSSL::Cipher.new(algo) }
66+
67+ cipher = engine.cipher(algo)
68+ cipher.encrypt
69+ cipher.key = key
70+ encrypted = cipher.update(data) + cipher.final
71+
72+ cipher = OpenSSL::Cipher.new(algo)
73+ cipher.decrypt
74+ cipher.key = key
75+ decrypted = cipher.update(encrypted) + cipher.final
76+
6877 assert_equal(data, decrypted)
6978 end;
7079 end
@@ -74,24 +83,9 @@ def test_openssl_engine_cipher_rc4
7483 # this is required because OpenSSL::Engine methods change global state
7584 def with_openssl ( code , **opts )
7685 assert_separately ( [ { "OSSL_MDEBUG" => nil } , "-ropenssl" ] , <<~"end;" , **opts )
77- require #{ __FILE__ . dump }
78- include OpenSSL::TestEngine::Utils
7986 #{ code }
8087 end;
8188 end
82-
83- module Utils
84- def get_engine
85- OpenSSL ::Engine . by_id ( "openssl" )
86- end
87-
88- def crypt_data ( data , key , mode )
89- cipher = yield
90- cipher . send mode
91- cipher . key = key
92- cipher . update ( data ) + cipher . final
93- end
94- end
9589end
9690
9791end
0 commit comments