tls package¶
Subpackages¶
Submodules¶
tls.alert_message module¶
tls.ciphersuites module¶
tls.exceptions module¶
tls.hello_message module¶
-
class
tls.hello_message.
ClientHello
(*args, **kw)¶ Bases:
object
An object representing a ClientHello message.
-
classmethod
from_bytes
(bytes)¶ Parse a
ClientHello
struct.Parameters: bytes – the bytes representing the input. Returns: ClientHello object.
-
classmethod
-
class
tls.hello_message.
Extension
(*args, **kw)¶ Bases:
object
An object representing an Extension struct.
tls.message module¶
-
class
tls.message.
Certificate
(*args, **kw)¶ Bases:
object
An object representing a Certificate struct.
-
classmethod
from_bytes
(bytes)¶ Parse a
Certificate
struct.Parameters: bytes – the bytes representing the input. Returns: Certificate object.
-
classmethod
-
class
tls.message.
CertificateRequest
(*args, **kw)¶ Bases:
object
An object representing a CertificateRequest struct.
-
classmethod
from_bytes
(bytes)¶ Parse a
CertificateRequest
struct.Parameters: bytes – the bytes representing the input. Returns: CertificateRequest object.
-
classmethod
-
class
tls.message.
Handshake
(*args, **kw)¶ Bases:
object
An object representing a Handshake struct.
-
classmethod
from_bytes
(bytes)¶ Parse a
Handshake
struct.Parameters: bytes – the bytes representing the input. Returns: Handshake object.
-
classmethod
-
class
tls.message.
PreMasterSecret
(*args, **kw)¶ Bases:
object
An object representing a PreMasterSecret struct.
-
classmethod
from_bytes
(bytes)¶ Parse a
PreMasterSecret
struct.Parameters: bytes – the bytes representing the input. Returns: CertificateRequest object.
-
classmethod
tls.record module¶
-
class
tls.record.
ProtocolVersion
(*args, **kw)¶ Bases:
object
An object representing a ProtocolVersion struct.
-
class
tls.record.
TLSCiphertext
(*args, **kw)¶ Bases:
object
An object representing a TLSCiphertext struct.
-
classmethod
from_bytes
(bytes)¶ Parse a
TLSCiphertext
struct.Parameters: bytes – the bytes representing the input. Returns: TLSCiphertext object.
-
classmethod
tls.utils module¶
-
tls.utils.
EnumClass
(type_field, type_enum)¶ Maps the members of an
enum.Enum
to a single kind ofconstruct.Construct
.Parameters: - type_field (
construct.Construct
) – The construct that represents the enum’s members. The type of this should correspond to the enum members’ types; for instance, an enum with a maximum value of 65535 would use aconstruct.macros.UBInt16
. - type_enum (
enum.Enum
) – The enum to encode and decode.
- type_field (
-
tls.utils.
EnumSwitch
(type_field, type_enum, value_field, value_choices)¶ Maps the members of an
enum.Enum
to arbitraryconstruct.Constructs()
. It returns a tuple intended to be spliced into anotherconstruct.Construct()
‘s definition:>>> from tls.utils import EnumSwitch >>> import construct, enum >>> class IntEnum(enum.Enum): ... VALUE = 1 ... >>> construct.Struct( ... "name", ... construct.UBInt8("an_integer"), ... *EnumSwitch(type_field=construct.UBInt8("type"), ... type_enum=IntEnum, ... value_field="value", ... value_choices={ ... IntEnum.VALUE: construct.UBInt8("first"), ... }) ... ) ... Struct('name')
Parameters: - type_field (
construct.Construct
) – The construct that represents the enum’s members. The type of this should correspond to the enum members’ types, so an enum with a maximum value of 65535, for example, would use aconstruct.macros.UBInt16
. - type_enum (
enum.Enum
) – The enum to encode and decode. - value_field (
str
) – The attribute name under which this value will be accessible. - value_choices (
dict
) – A dictionary that maps members of type_enum to subconstructs. This followsconstruct.core.Switch()
‘s API, so_default_
will match any members without an explicit mapping.
Returns: A
tuple
of the form (EnumClass()
,construct.core.Switch()
)- type_field (
-
tls.utils.
PrefixedBytes
(name, length_field=FormatField('length'))¶ Length-prefixed binary data. This is like a
construct.macros.PascalString()
that raises aconstrcut.AdaptationError
when encoding something other thanbytes
.Parameters: - name (
str
) – The attribute name under which this value will be accessible. - length_field (a
construct.core.FormatField
) – (optional) The prefixed length field. Defaults toconstruct.macros.UBInt8()
.
- name (
-
tls.utils.
TLSPrefixedArray
(subconn, length_name='length')¶ The TLS vector type. It specializes on another
construct.Construct
and then encodes or decodes an arbitrarily long list or array of those constructs, prepending or reading a leading 16 bit length.Parameters: - subconn (construct.Construct) – The construct this array contains.
- length_field (
str
) – (optional) The attribute name under which theconstruct.macros.UBInt16
representing this array’s length will be accessible. You do not need to provide this when encoding a python sequence!