Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test/openssl/test_pkey_ec.rb: refactor tests for EC.builtin_curves #675

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions test/openssl/test_pkey_ec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,6 @@

class OpenSSL::TestEC < OpenSSL::PKeyTestCase
def test_ec_key
builtin_curves = OpenSSL::PKey::EC.builtin_curves
assert_not_empty builtin_curves

builtin_curves.each do |curve_name, comment|
# Oakley curves and X25519 are not suitable for signing and causes
# FIPS-selftest failure on some environment, so skip for now.
next if ["Oakley", "X25519"].any? { |n| curve_name.start_with?(n) }

key = OpenSSL::PKey::EC.generate(curve_name)
assert_predicate key, :private?
assert_predicate key, :public?
assert_nothing_raised { key.check_key }
end

key1 = OpenSSL::PKey::EC.generate("prime256v1")

# PKey is immutable in OpenSSL >= 3.0; constructing an empty EC object is
Expand Down Expand Up @@ -49,6 +35,17 @@ def test_ec_key
end
end

def test_builtin_curves
builtin_curves = OpenSSL::PKey::EC.builtin_curves
assert_not_empty builtin_curves
assert_equal 2, builtin_curves[0].size
assert_kind_of String, builtin_curves[0][0]
assert_kind_of String, builtin_curves[0][1]

builtin_curve_names = builtin_curves.map { |name, comment| name }
assert_include builtin_curve_names, "prime256v1"
end

def test_generate
assert_raise(OpenSSL::PKey::ECError) { OpenSSL::PKey::EC.generate("non-existent") }
g = OpenSSL::PKey::EC::Group.new("prime256v1")
Expand Down