Added new test cases for PKCS#8 parsing (#12305)

This commit is contained in:
Alex Gaynor 2025-01-17 23:00:29 -05:00 committed by GitHub
parent 66fbfb2242
commit 86b24873c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 23 additions and 0 deletions

View file

@ -189,6 +189,10 @@ Custom asymmetric vectors
``TEST(DSATest, NilpotentGenerator)``).
* ``asymmetric/PKCS8/ec-invalid-private-scalar.pem`` - Contains a PKCS8 encoded
PEM with a ``secp256r1`` OID and an invalid (very large) private scalar.
* ``asymmetric/PKCS8/invalid-version.der`` - Contains a PKCS8 encoded DER with
an invalid version field.
* ``asymmetric/PKCS8/unknown-oid.der`` - Contains a PKCS8 encoded DER with an
unknown OID.
Key exchange

View file

@ -405,6 +405,25 @@ class TestDERSerialization:
with pytest.raises(ValueError):
load_der_parameters(param_data, backend)
@pytest.mark.xfail()
def test_load_pkcs8_private_key_invalid_version(self):
data = load_vectors_from_file(
os.path.join("asymmetric", "PKCS8", "invalid-version.der"),
lambda f: f.read(),
mode="rb",
)
with pytest.raises(ValueError):
load_der_private_key(data, password=None)
def test_load_pkcs8_private_key_unknown_oid(self):
data = load_vectors_from_file(
os.path.join("asymmetric", "PKCS8", "unknown-oid.der"),
lambda f: f.read(),
mode="rb",
)
with pytest.raises(ValueError):
load_der_private_key(data, password=None)
class TestPEMSerialization:
@pytest.mark.parametrize(