Skip to content

Commit

Permalink
Added new test cases for PKCS#8 parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Jan 17, 2025
1 parent 06065d4 commit ab97740
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/development/test-vectors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions tests/hazmat/primitives/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,25 @@ def test_wrong_parameters_format(self, backend):
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(
Expand Down

0 comments on commit ab97740

Please sign in to comment.