summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2024-07-04 17:28:10 +0900
committergit <svn-admin@ruby-lang.org>2025-01-06 17:07:56 +0000
commitff708f86fadd891869a96320f1de499dee1b1046 (patch)
tree369482d24000884dbdc9cb95b295955d44b251b6
parentf0095413a520140d2ba54728d3e558d75dfda09d (diff)
[ruby/openssl] 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. https://github.com/ruby/openssl/commit/2f807ff30f
-rw-r--r--test/openssl/fixtures/pkey/p256_too_large.pem5
-rw-r--r--test/openssl/fixtures/pkey/p384_invalid.pem6
-rw-r--r--test/openssl/test_pkey_ec.rb12
3 files changed, 8 insertions, 15 deletions
diff --git a/test/openssl/fixtures/pkey/p256_too_large.pem b/test/openssl/fixtures/pkey/p256_too_large.pem
deleted file mode 100644
index a73ac37f87..0000000000
--- a/test/openssl/fixtures/pkey/p256_too_large.pem
+++ /dev/null
@@ -1,5 +0,0 @@
------BEGIN EC PRIVATE KEY-----
-MHcCAQEEIP+TT0V8Fndsnacji9tyf6hmhHywcOWTee9XkiBeJoVloAoGCCqGSM49
-AwEHoUQDQgAEBkhhJIU/2/YdPSlY2I1k25xjK4trr5OXSgXvBC21PtY0HQ7lor7A
-jzT0giJITqmcd81fwGw5+96zLcdxTF1hVQ==
------END EC PRIVATE KEY-----
diff --git a/test/openssl/fixtures/pkey/p384_invalid.pem b/test/openssl/fixtures/pkey/p384_invalid.pem
deleted file mode 100644
index d5cdc9a3af..0000000000
--- a/test/openssl/fixtures/pkey/p384_invalid.pem
+++ /dev/null
@@ -1,6 +0,0 @@
------BEGIN EC PRIVATE KEY-----
-MIGkAgEBBDDA1Tm0m7YhkfeVpFuarAJYVlHp2tQj+1fOBiLa10t9E8TiQO/hVfxB
-vGaVEQwOheWgBwYFK4EEACKhZANiAASyGqmryZGqdpsq5gEDIfNvgC3AwSJxiBCL
-XKHBTFRp+tCezLDOK/6V8KK/vVGBJlGFW6/I7ahyXprxS7xs7hPA9iz5YiuqXlu+
-lbrIpZOz7b73hyQQCkvbBO/Avg+hPAk=
------END EC PRIVATE KEY-----
diff --git a/test/openssl/test_pkey_ec.rb b/test/openssl/test_pkey_ec.rb
index 2cb8e287ab..5a15c54415 100644
--- a/test/openssl/test_pkey_ec.rb
+++ b/test/openssl/test_pkey_ec.rb
@@ -88,12 +88,16 @@ class OpenSSL::TestEC < OpenSSL::PKeyTestCase
assert_equal(true, key2.check_key)
# Behavior of EVP_PKEY_public_check changes between OpenSSL 1.1.1 and 3.0
- key4 = Fixtures.pkey("p256_too_large")
+ # The public key does not match the private key
+ key4 = OpenSSL::PKey.read(<<~EOF)
+ -----BEGIN EC PRIVATE KEY-----
+ MHcCAQEEIP+TT0V8Fndsnacji9tyf6hmhHywcOWTee9XkiBeJoVloAoGCCqGSM49
+ AwEHoUQDQgAEBkhhJIU/2/YdPSlY2I1k25xjK4trr5OXSgXvBC21PtY0HQ7lor7A
+ jzT0giJITqmcd81fwGw5+96zLcdxTF1hVQ==
+ -----END EC PRIVATE KEY-----
+ EOF
assert_raise(OpenSSL::PKey::ECError) { key4.check_key }
- key5 = Fixtures.pkey("p384_invalid")
- assert_raise(OpenSSL::PKey::ECError) { key5.check_key }
-
# EC#private_key= is deprecated in 3.0 and won't work on OpenSSL 3.0
if !openssl?(3, 0, 0)
key2.private_key += 1