Skip to content

Commit

Permalink
fix formatting/indentation in extensions module
Browse files Browse the repository at this point in the history
fix indentation levels, remove unnecessary "\" between brackets,
make block comments start with "# ", insert double newline before
class definitions
  • Loading branch information
tomato42 committed Jun 28, 2018
1 parent 07e92d3 commit 5a33fa6
Showing 1 changed file with 48 additions and 43 deletions.
91 changes: 48 additions & 43 deletions tlslite/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
"""

from __future__ import generators
from .utils.codec import Writer, Parser
from collections import namedtuple
from .utils.codec import Writer, Parser
from .constants import NameType, ExtensionType, CertificateStatusType, \
SignatureAlgorithm, HashAlgorithm, SignatureScheme, \
PskKeyExchangeMode, CertificateType, GroupName, ECPointFormat
from .errors import TLSInternalError


class TLSExtension(object):
"""
Base class for handling handshake protocol hello messages extensions.
Expand Down Expand Up @@ -90,7 +91,7 @@ class TLSExtension(object):
# actual definition at the end of file, after definitions of all classes
_universalExtensions = {}
_serverExtensions = {}
#_encryptedExtensions = {}
# _encryptedExtensions = {}
_certificateExtensions = {}
_hrrExtensions = {}

Expand Down Expand Up @@ -226,7 +227,7 @@ def parse(self, p):

for handler_t, handlers in (
(self.cert, self._certificateExtensions),
#(self.encExtType, self._encryptedExtensions),
# (self.encExtType, self._encryptedExtensions),
(self.serverType, self._serverExtensions),
(self.hrr, self._hrrExtensions),
(True, self._universalExtensions)):
Expand Down Expand Up @@ -254,8 +255,7 @@ def __eq__(self, that):
if hasattr(that, 'extType') and hasattr(that, 'extData'):
return self.extType == that.extType and \
self.extData == that.extData
else:
return False
return False

def __repr__(self):
"""Output human readable representation of object
Expand All @@ -266,10 +266,10 @@ def __repr__(self):
:rtype: str
"""
return "TLSExtension(extType={0!r}, extData={1!r},"\
" serverType={2!r}, encExtType={3!r})".format(self.extType,
self.extData,
self.serverType,
self.encExtType)
" serverType={2!r}, encExtType={3!r})".format(self.extType,
self.extData,
self.serverType,
self.encExtType)


class CustomNameExtension(TLSExtension):
Expand Down Expand Up @@ -651,13 +651,13 @@ def create(self, hostname=None, hostNames=None, serverNames=None):
self.serverNames = []

if hostname:
self.serverNames += [SNIExtension.ServerName(NameType.host_name,\
hostname)]
self.serverNames += \
[SNIExtension.ServerName(NameType.host_name, hostname)]

if hostNames:
self.serverNames +=\
[SNIExtension.ServerName(NameType.host_name, x) for x in\
hostNames]
self.serverNames += \
[SNIExtension.ServerName(NameType.host_name, x) for x in
hostNames]

if serverNames:
self.serverNames += serverNames
Expand All @@ -674,9 +674,8 @@ def hostNames(self):
# an immutable type
if self.serverNames is None:
return tuple()
else:
return tuple([x.name for x in self.serverNames if \
x.name_type == NameType.host_name])
return tuple([x.name for x in self.serverNames if
x.name_type == NameType.host_name])

@hostNames.setter
def hostNames(self, hostNames):
Expand All @@ -691,19 +690,18 @@ def hostNames(self, hostNames):
"""

self.serverNames = \
[SNIExtension.ServerName(NameType.host_name, x) for x in \
hostNames] + \
[x for x in self.serverNames if \
x.name_type != NameType.host_name]
[SNIExtension.ServerName(NameType.host_name, x) for x in
hostNames] + \
[x for x in self.serverNames if x.name_type != NameType.host_name]

@hostNames.deleter
def hostNames(self):
"""
Remove all host names from extension, leaves other name types
unmodified.
"""
self.serverNames = [x for x in self.serverNames if \
x.name_type != NameType.host_name]
self.serverNames = [x for x in self.serverNames if
x.name_type != NameType.host_name]

@property
def extData(self):
Expand Down Expand Up @@ -795,11 +793,10 @@ class SupportedVersionsExtension(VarSeqListExtension):

def __init__(self):
"""Create an instance of SupportedVersionsExtension."""
super(SupportedVersionsExtension, self).__init__(1, 2, 1,
"versions",
extType=
ExtensionType.
supported_versions)
super(SupportedVersionsExtension, self).__init__(
1, 2, 1,
"versions",
extType=ExtensionType.supported_versions)


class SrvSupportedVersionsExtension(TLSExtension):
Expand Down Expand Up @@ -901,6 +898,7 @@ def __init__(self):
ExtensionType.cert_type,
CertificateType)


class ServerCertTypeExtension(TLSExtension):
"""
This class handles the Certificate Type extension (variant sent by server)
Expand All @@ -922,16 +920,18 @@ def __init__(self):
See also: :py:meth:`create` and :py:meth:`parse`
"""
super(ServerCertTypeExtension, self).__init__(server=True, \
extType=ExtensionType.cert_type)
super(ServerCertTypeExtension, self).__init__(
server=True,
extType=ExtensionType.cert_type)
self.cert_type = None

def __repr__(self):
""" Return programmer-centric description of object
:rtype: str
"""
return "ServerCertTypeExtension(cert_type={0!r})".format(self.cert_type)
return "ServerCertTypeExtension(cert_type={0!r})"\
.format(self.cert_type)

@property
def extData(self):
Expand Down Expand Up @@ -967,6 +967,7 @@ def parse(self, p):

return self


class SRPExtension(TLSExtension):
"""
This class handles the Secure Remote Password protocol TLS extension
Expand Down Expand Up @@ -1051,6 +1052,7 @@ def parse(self, p):

return self


class NPNExtension(TLSExtension):
"""
This class handles the unofficial Next Protocol Negotiation TLS extension.
Expand Down Expand Up @@ -1124,6 +1126,7 @@ def parse(self, p):

return self


class TACKExtension(TLSExtension):
"""
This class handles the server side TACK extension (see
Expand Down Expand Up @@ -1158,14 +1161,14 @@ def __repr__(self):
:rtype: str
"""
return "TACK(public_key={0!r}, min_generation={1!r}, "\
"generation={2!r}, expiration={3!r}, target_hash={4!r}, "\
"signature={5!r})".format(
self.public_key, self.min_generation,
self.generation, self.expiration, self.target_hash,
self.signature)
"generation={2!r}, expiration={3!r}, target_hash={4!r}, "\
"signature={5!r})"\
.format(self.public_key, self.min_generation,
self.generation, self.expiration, self.target_hash,
self.signature)

def create(self, public_key, min_generation, generation, expiration,
target_hash, signature):
target_hash, signature):
"""
Initialise the TACK with data
"""
Expand Down Expand Up @@ -1258,8 +1261,8 @@ def __repr__(self):
:rtype: str
"""
return "TACKExtension(activation_flags={0!r}, tacks={1!r})".format(
self.activation_flags, self.tacks)
return "TACKExtension(activation_flags={0!r}, tacks={1!r})"\
.format(self.activation_flags, self.tacks)

@property
def extData(self):
Expand Down Expand Up @@ -1308,6 +1311,7 @@ def parse(self, p):

return self


class SupportedGroupsExtension(VarListExtension):
"""
Client side list of supported groups of (EC)DHE key exchage.
Expand Down Expand Up @@ -1505,7 +1509,8 @@ def __repr__(self):
:rtype: str
"""
return "ALPNExtension(protocol_names={0!r})".format(self.protocol_names)
return "ALPNExtension(protocol_names={0!r})"\
.format(self.protocol_names)

@property
def extData(self):
Expand Down Expand Up @@ -1576,9 +1581,9 @@ class StatusRequestExtension(TLSExtension):
"""

def __init__(self):
super(StatusRequestExtension, self).__init__(
extType=ExtensionType.status_request)
"""Create instance of StatusRequestExtension."""
super(StatusRequestExtension, self).__init__(
extType=ExtensionType.status_request)
self.status_type = None
self.responder_id_list = []
self.request_extensions = bytearray()
Expand Down Expand Up @@ -1671,7 +1676,7 @@ class CertificateStatusExtension(TLSExtension):
def __init__(self):
"""Create instance of CertificateStatusExtension."""
super(CertificateStatusExtension, self).__init__(
extType=ExtensionType.status_request)
extType=ExtensionType.status_request)
self.status_type = None
self.response = None

Expand Down

0 comments on commit 5a33fa6

Please sign in to comment.