Skip to content

Commit 2f807ff

Browse files
committed
pkey/ec: use heredoc for invalid key example in test cases
test/openssl/fixtures/pkey/p256_too_large.pem and p384_invalid.pem are invalid keys where the encoded public key doesn't match the private key. They are only useful for test cases for OpenSSL::PKey::EC#check_key and will not be reused elsewhere. Let's directly include the PEM encoding as a heredoc for clarity. p384_invalid.pem is dropped because it is redundant.
1 parent 11216b8 commit 2f807ff

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

test/openssl/fixtures/pkey/p256_too_large.pem

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/openssl/fixtures/pkey/p384_invalid.pem

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/openssl/test_pkey_ec.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,16 @@ def test_check_key
8888
assert_equal(true, key2.check_key)
8989

9090
# Behavior of EVP_PKEY_public_check changes between OpenSSL 1.1.1 and 3.0
91-
key4 = Fixtures.pkey("p256_too_large")
91+
# The public key does not match the private key
92+
key4 = OpenSSL::PKey.read(<<~EOF)
93+
-----BEGIN EC PRIVATE KEY-----
94+
MHcCAQEEIP+TT0V8Fndsnacji9tyf6hmhHywcOWTee9XkiBeJoVloAoGCCqGSM49
95+
AwEHoUQDQgAEBkhhJIU/2/YdPSlY2I1k25xjK4trr5OXSgXvBC21PtY0HQ7lor7A
96+
jzT0giJITqmcd81fwGw5+96zLcdxTF1hVQ==
97+
-----END EC PRIVATE KEY-----
98+
EOF
9299
assert_raise(OpenSSL::PKey::ECError) { key4.check_key }
93100

94-
key5 = Fixtures.pkey("p384_invalid")
95-
assert_raise(OpenSSL::PKey::ECError) { key5.check_key }
96-
97101
# EC#private_key= is deprecated in 3.0 and won't work on OpenSSL 3.0
98102
if !openssl?(3, 0, 0)
99103
key2.private_key += 1

0 commit comments

Comments
 (0)