Skip to content

Commit 84def59

Browse files
committed
fixes #13812 -- have Name.__repr__ put things in RFC4514 order
1 parent b2191aa commit 84def59

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/cryptography/x509/name.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,7 @@ def __len__(self) -> int:
366366
return sum(len(rdn) for rdn in self._attributes)
367367

368368
def __repr__(self) -> str:
369-
rdns = ",".join(attr.rfc4514_string() for attr in self._attributes)
370-
return f"<Name({rdns})>"
369+
return f"<Name({self.rfc4514_string()})>"
371370

372371

373372
class _RFC4514NameParser:

tests/x509/test_x509.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,15 +1694,15 @@ def test_public_bytes_match(
16941694
serialized = cert.public_bytes(encoding)
16951695
assert serialized == cert_bytes
16961696

1697-
def test_certificate_repr(self, backend):
1697+
def test_certificate_repr(self):
16981698
cert = _load_cert(
16991699
os.path.join("x509", "cryptography.io.pem"),
17001700
x509.load_pem_x509_certificate,
17011701
)
17021702
assert repr(cert) == (
1703-
"<Certificate(subject=<Name(OU=GT48742965,OU=See www.rapidssl.com"
1704-
"/resources/cps (c)14,OU=Domain Control Validated - RapidSSL(R),"
1705-
"CN=www.cryptography.io)>, ...)>"
1703+
"<Certificate(subject=<Name(CN=www.cryptography.io,OU=Domain "
1704+
"Control Validated - RapidSSL(R),OU=See "
1705+
"www.rapidssl.com/resources/cps (c)14,OU=GT48742965)>, ...)>"
17061706
)
17071707

17081708
def test_parse_tls_feature_extension(self, backend):
@@ -5790,7 +5790,7 @@ def test_load_ecdsa_cert_null_alg_params(self, backend):
57905790
assert isinstance(cert.signature_hash_algorithm, hashes.SHA256)
57915791
assert isinstance(cert.public_key(), ec.EllipticCurvePublicKey)
57925792

5793-
def test_load_bitstring_dn(self, backend):
5793+
def test_load_bitstring_dn(self):
57945794
cert = _load_cert(
57955795
os.path.join("x509", "scottishpower-bitstring-dn.pem"),
57965796
x509.load_pem_x509_certificate,
@@ -5809,7 +5809,7 @@ def test_load_bitstring_dn(self, backend):
58095809
]
58105810
)
58115811
assert repr(cert.subject) == (
5812-
"<Name(CN=ScottishPower,OU=02,2.5.4.45=#0070b3d51f305f0001)>"
5812+
"<Name(2.5.4.45=#0070b3d51f305f0001,OU=02,CN=ScottishPower)>"
58135813
)
58145814

58155815
def test_load_name_attribute_long_form_asn1_tag(self, backend):
@@ -6409,12 +6409,12 @@ def test_rdns(self):
64096409
(
64106410
"cryptography.io",
64116411
"PyCA",
6412-
"<Name(CN=cryptography.io,O=PyCA)>",
6412+
"<Name(O=PyCA,CN=cryptography.io)>",
64136413
),
64146414
(
64156415
"Certificación",
64166416
"Certificación",
6417-
"<Name(CN=Certificación,O=Certificación)>",
6417+
"<Name(O=Certificación,CN=Certificación)>",
64186418
),
64196419
],
64206420
)

0 commit comments

Comments
 (0)