Skip to content

Commit e0ff759

Browse files
committed
Merge branch 'maint-3.1' into maint-3.2
* maint-3.1: pkey: avoid calling i2d_PUBKEY family on an incomplete key Cleanup Gemfile test/openssl/test_ossl.rb: use clock_gettime for measuring time Backport changes related to extracted stdlibs in Ruby 3.4-3.5
2 parents 2d7247e + c48bb75 commit e0ff759

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

Gemfile

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
source "https://rubygems.org"
22

3-
group :development do
4-
gem "rake"
5-
gem "rake-compiler"
6-
gem "test-unit", "~> 3.0", ">= 3.4.6"
7-
gem "test-unit-ruby-core"
8-
# In the case of Ruby whose rdoc is not a default gem.
9-
gem "rdoc"
10-
end
3+
gem "rake"
4+
gem "rake-compiler"
5+
gem "test-unit", "~> 3.0", ">= 3.4.6"
6+
gem "test-unit-ruby-core"
7+
gem "prime"
8+
gem "rdoc"

ext/openssl/ossl_pkey.c

+1
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,7 @@ ossl_pkey_export_spki(VALUE self, int to_der)
937937
BIO *bio;
938938

939939
GetPKey(self, pkey);
940+
ossl_pkey_check_public_key(pkey);
940941
bio = BIO_new(BIO_s_mem());
941942
if (!bio)
942943
ossl_raise(ePKeyError, "BIO_new");

test/openssl/test_ossl.rb

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# frozen_string_literal: true
22
require_relative "utils"
33

4-
require 'benchmark'
5-
64
if defined?(OpenSSL)
75

86
class OpenSSL::OSSL < OpenSSL::SSLTestCase
@@ -54,8 +52,14 @@ def test_memcmp_timing
5452

5553
a_b_time = a_c_time = 0
5654
100.times do
57-
a_b_time += Benchmark.measure { 100.times { OpenSSL.fixed_length_secure_compare(a, b) } }.real
58-
a_c_time += Benchmark.measure { 100.times { OpenSSL.fixed_length_secure_compare(a, c) } }.real
55+
t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
56+
100.times { OpenSSL.fixed_length_secure_compare(a, b) }
57+
t2 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
58+
100.times { OpenSSL.fixed_length_secure_compare(a, c) }
59+
t3 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
60+
61+
a_b_time += t2 - t1
62+
a_c_time += t3 - t2
5963
end
6064
assert_operator(a_b_time, :<, a_c_time * 10, "fixed_length_secure_compare timing test failed")
6165
assert_operator(a_c_time, :<, a_b_time * 10, "fixed_length_secure_compare timing test failed")

test/openssl/test_pkey_dsa.rb

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ def test_new_break
2828
end
2929
end
3030

31+
def test_new_empty
32+
key = OpenSSL::PKey::DSA.new
33+
assert_nil(key.p)
34+
assert_raise(OpenSSL::PKey::PKeyError) { key.to_der }
35+
end
36+
3137
def test_generate
3238
# DSA.generate used to call DSA_generate_parameters_ex(), which adjusts the
3339
# size of q according to the size of p

0 commit comments

Comments
 (0)