diff --git a/asn1crypto/x509.py b/asn1crypto/x509.py index a67ab1a..38aa770 100644 --- a/asn1crypto/x509.py +++ b/asn1crypto/x509.py @@ -27,7 +27,7 @@ from ._errors import unwrap from ._iri import iri_to_uri, uri_to_iri from ._ordereddict import OrderedDict -from ._types import type_name, str_cls, bytes_to_list +from ._types import type_name, str_cls, byte_cls, bytes_to_list from .algos import AlgorithmIdentifier, AnyAlgorithmIdentifier, DigestAlgorithm, SignedDigestAlgorithm from .core import ( Any, @@ -708,7 +708,13 @@ def prepped_value(self): """ if self._prepped is None: - self._prepped = self._ldap_string_prep(self['value'].native) + native = self['value'].native + if isinstance(native, str_cls): + self._prepped = self._ldap_string_prep(native) + else: + if isinstance(native, byte_cls): + native = ' ' + native.decode('cp1252') + ' ' + self._prepped = native return self._prepped def __ne__(self, other): diff --git a/tests/test_x509.py b/tests/test_x509.py index c177fe6..43e0bea 100644 --- a/tests/test_x509.py +++ b/tests/test_x509.py @@ -485,6 +485,23 @@ def test_build_name_type_by_oid(self): self.assertEqual("unique_identifier", complex_name.chosen[3][0]['type'].native) self.assertIsInstance(complex_name.chosen[3][0]['value'], core.OctetBitString) + def test_name_hashable(self): + complex_name = x509.Name.build( + { + 'country_name': 'US', + 'tpm_manufacturer': 'Acme Co', + 'unique_identifier': b'\x04\x10\x03\x09', + 'email_address': 'will@codexns.io' + } + ) + self.assertEqual( + "country_name: us \x1e" + "email_address: will@codexns.io \x1e" + "tpm_manufacturer: acme co \x1e" + "unique_identifier: \x04\x10\x03\x09 ", + complex_name.hashable + ) + def test_v1_cert(self): cert = self._load_cert('chromium/ndn.ca.crt') tbs_cert = cert['tbs_certificate']