summaryrefslogtreecommitdiff
path: root/src/cryptography
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2020-07-26 12:07:31 -0500
committerGitHub <noreply@github.com>2020-07-26 13:07:31 -0400
commitace8a92be9ab5f4b65d25191d25bb690be5e2338 (patch)
treeeb6b8621cb8e56bbfe15fbd690bd066fa8f1e170 /src/cryptography
parent442926c60cdf4343028e47d5bfd92d97b98e1429 (diff)
downloadcryptography-ace8a92be9ab5f4b65d25191d25bb690be5e2338.tar.gz
remove idna support finally (#5351)
* remove idna support finally * remove unused import
Diffstat (limited to 'src/cryptography')
-rw-r--r--src/cryptography/x509/general_name.py82
1 files changed, 6 insertions, 76 deletions
diff --git a/src/cryptography/x509/general_name.py b/src/cryptography/x509/general_name.py
index 5336a10f6..9be9d8c99 100644
--- a/src/cryptography/x509/general_name.py
+++ b/src/cryptography/x509/general_name.py
@@ -6,11 +6,9 @@ from __future__ import absolute_import, division, print_function
import abc
import ipaddress
-import warnings
from email.utils import parseaddr
import six
-from six.moves import urllib_parse
from cryptography import utils
from cryptography.x509.name import Name
@@ -30,21 +28,6 @@ _GENERAL_NAMES = {
}
-def _lazy_import_idna():
- # Import idna lazily becase it allocates a decent amount of memory, and
- # we're only using it in deprecated paths.
- try:
- import idna
-
- return idna
- except ImportError:
- raise ImportError(
- "idna is not installed, but a deprecated feature that requires it"
- " was used. See: https://cryptography.io/en/latest/faq/#importe"
- "rror-idna-is-not-installed"
- )
-
-
class UnsupportedGeneralNameType(Exception):
def __init__(self, msg, type):
super(UnsupportedGeneralNameType, self).__init__(msg)
@@ -67,14 +50,10 @@ class RFC822Name(object):
try:
value.encode("ascii")
except UnicodeEncodeError:
- value = self._idna_encode(value)
- warnings.warn(
+ raise ValueError(
"RFC822Name values should be passed as an A-label string. "
"This means unicode characters should be encoded via "
- "idna. Support for passing unicode strings (aka U-label) "
- "will be removed in a future version.",
- utils.PersistentlyDeprecated2017,
- stacklevel=2,
+ "a library like idna."
)
else:
raise TypeError("value must be string")
@@ -95,12 +74,6 @@ class RFC822Name(object):
instance._value = value
return instance
- def _idna_encode(self, value):
- idna = _lazy_import_idna()
- _, address = parseaddr(value)
- parts = address.split(u"@")
- return parts[0] + "@" + idna.encode(parts[1]).decode("ascii")
-
def __repr__(self):
return "<RFC822Name(value={0!r})>".format(self.value)
@@ -117,16 +90,6 @@ class RFC822Name(object):
return hash(self.value)
-def _idna_encode(value):
- idna = _lazy_import_idna()
- # Retain prefixes '*.' for common/alt names and '.' for name constraints
- for prefix in ["*.", "."]:
- if value.startswith(prefix):
- value = value[len(prefix) :]
- return prefix + idna.encode(value).decode("ascii")
- return idna.encode(value).decode("ascii")
-
-
@utils.register_interface(GeneralName)
class DNSName(object):
def __init__(self, value):
@@ -134,14 +97,10 @@ class DNSName(object):
try:
value.encode("ascii")
except UnicodeEncodeError:
- value = _idna_encode(value)
- warnings.warn(
+ raise ValueError(
"DNSName values should be passed as an A-label string. "
"This means unicode characters should be encoded via "
- "idna. Support for passing unicode strings (aka U-label) "
- "will be removed in a future version.",
- utils.PersistentlyDeprecated2017,
- stacklevel=2,
+ "a library like idna."
)
else:
raise TypeError("value must be string")
@@ -179,14 +138,10 @@ class UniformResourceIdentifier(object):
try:
value.encode("ascii")
except UnicodeEncodeError:
- value = self._idna_encode(value)
- warnings.warn(
+ raise ValueError(
"URI values should be passed as an A-label string. "
"This means unicode characters should be encoded via "
- "idna. Support for passing unicode strings (aka U-label) "
- " will be removed in a future version.",
- utils.PersistentlyDeprecated2017,
- stacklevel=2,
+ "a library like idna."
)
else:
raise TypeError("value must be string")
@@ -201,31 +156,6 @@ class UniformResourceIdentifier(object):
instance._value = value
return instance
- def _idna_encode(self, value):
- idna = _lazy_import_idna()
- parsed = urllib_parse.urlparse(value)
- if parsed.port:
- netloc = (
- idna.encode(parsed.hostname)
- + ":{}".format(parsed.port).encode("ascii")
- ).decode("ascii")
- else:
- netloc = idna.encode(parsed.hostname).decode("ascii")
-
- # Note that building a URL in this fashion means it should be
- # semantically indistinguishable from the original but is not
- # guaranteed to be exactly the same.
- return urllib_parse.urlunparse(
- (
- parsed.scheme,
- netloc,
- parsed.path,
- parsed.params,
- parsed.query,
- parsed.fragment,
- )
- )
-
def __repr__(self):
return "<UniformResourceIdentifier(value={0!r})>".format(self.value)