File tree Expand file tree Collapse file tree 3 files changed +11
-9
lines changed Expand file tree Collapse file tree 3 files changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ Deprecations:
1616Changes:
1717^^^^^^^^
1818
19+ - Invalid versions are now rejected in ``OpenSSL.crypto.X509Req.set_version ``.
20+
192123.1.1 (2023-03-28)
2022-------------------
2123
Original file line number Diff line number Diff line change @@ -1010,6 +1010,12 @@ def set_version(self, version: int) -> None:
10101010 :param int version: The version number.
10111011 :return: ``None``
10121012 """
1013+ if not isinstance (version , int ):
1014+ raise TypeError ("version must be an int" )
1015+ if version != 0 :
1016+ raise ValueError (
1017+ "Invalid version. The only valid version for X509Req is 0."
1018+ )
10131019 set_result = _lib .X509_REQ_set_version (self ._req , version )
10141020 _openssl_assert (set_result == 1 )
10151021
Original file line number Diff line number Diff line change @@ -1601,20 +1601,12 @@ def test_version(self):
16011601 """
16021602 `X509Req.set_version` sets the X.509 version of the certificate
16031603 request. `X509Req.get_version` returns the X.509 version of the
1604- certificate request. The only defined version is 0. Others may or
1605- may not be supported depending on backend.
1604+ certificate request. The only defined version is 0.
16061605 """
16071606 request = X509Req ()
16081607 assert request .get_version () == 0
16091608 request .set_version (0 )
16101609 assert request .get_version () == 0
1611- try :
1612- request .set_version (1 )
1613- assert request .get_version () == 1
1614- request .set_version (3 )
1615- assert request .get_version () == 3
1616- except Error :
1617- pass
16181610
16191611 def test_version_wrong_args (self ):
16201612 """
@@ -1624,6 +1616,8 @@ def test_version_wrong_args(self):
16241616 request = X509Req ()
16251617 with pytest .raises (TypeError ):
16261618 request .set_version ("foo" )
1619+ with pytest .raises (ValueError ):
1620+ request .set_version (2 )
16271621
16281622 def test_get_subject (self ):
16291623 """
You can’t perform that action at this time.
0 commit comments