Skip to content

Commit

Permalink
Merge branch 'maint-3.2' into maint-3.3
Browse files Browse the repository at this point in the history
* maint-3.2:
  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
  • Loading branch information
rhenium committed Jan 29, 2025
2 parents a0bf65f + e0ff759 commit d974eda
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
15 changes: 6 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
source "https://rubygems.org"

group :development do
gem "rake"
gem "rake-compiler"
gem "test-unit", "~> 3.0", ">= 3.4.6"
gem "test-unit-ruby-core"
gem "prime"
# In the case of Ruby whose rdoc is not a default gem.
gem "rdoc"
end
gem "rake"
gem "rake-compiler"
gem "test-unit", "~> 3.0", ">= 3.4.6"
gem "test-unit-ruby-core"
gem "prime"
gem "rdoc"
1 change: 1 addition & 0 deletions ext/openssl/ossl_pkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,7 @@ ossl_pkey_export_spki(VALUE self, int to_der)
BIO *bio;

GetPKey(self, pkey);
ossl_pkey_check_public_key(pkey);
bio = BIO_new(BIO_s_mem());
if (!bio)
ossl_raise(ePKeyError, "BIO_new");
Expand Down
10 changes: 8 additions & 2 deletions test/openssl/test_ossl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ def test_memcmp_timing

a_b_time = a_c_time = 0
100.times do
a_b_time += Benchmark.measure { 100.times { OpenSSL.fixed_length_secure_compare(a, b) } }.real
a_c_time += Benchmark.measure { 100.times { OpenSSL.fixed_length_secure_compare(a, c) } }.real
t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
100.times { OpenSSL.fixed_length_secure_compare(a, b) }
t2 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
100.times { OpenSSL.fixed_length_secure_compare(a, c) }
t3 = Process.clock_gettime(Process::CLOCK_MONOTONIC)

a_b_time += t2 - t1
a_c_time += t3 - t2
end
assert_operator(a_b_time, :<, a_c_time * 10, "fixed_length_secure_compare timing test failed")
assert_operator(a_c_time, :<, a_b_time * 10, "fixed_length_secure_compare timing test failed")
Expand Down
6 changes: 6 additions & 0 deletions test/openssl/test_pkey_dsa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ def test_new_break
end
end

def test_new_empty
key = OpenSSL::PKey::DSA.new
assert_nil(key.p)
assert_raise(OpenSSL::PKey::PKeyError) { key.to_der }
end

def test_generate
# DSA.generate used to call DSA_generate_parameters_ex(), which adjusts the
# size of q according to the size of p
Expand Down

0 comments on commit d974eda

Please sign in to comment.