partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | HPackZString.huffman_decode | huffman_decode decodes the bitstring provided as parameters.
@param int i: the bitstring to decode
@param int ibl: the bitlength of i
@return str: the string decoded from the bitstring
@raise AssertionError, InvalidEncodingException | scapy/contrib/http2.py | def huffman_decode(cls, i, ibl):
# type: (int, int) -> str
""" huffman_decode decodes the bitstring provided as parameters.
@param int i: the bitstring to decode
@param int ibl: the bitlength of i
@return str: the string decoded from the bitstring
@raise AssertionError, ... | def huffman_decode(cls, i, ibl):
# type: (int, int) -> str
""" huffman_decode decodes the bitstring provided as parameters.
@param int i: the bitstring to decode
@param int ibl: the bitlength of i
@return str: the string decoded from the bitstring
@raise AssertionError, ... | [
"huffman_decode",
"decodes",
"the",
"bitstring",
"provided",
"as",
"parameters",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L1053-L1108 | [
"def",
"huffman_decode",
"(",
"cls",
",",
"i",
",",
"ibl",
")",
":",
"# type: (int, int) -> str",
"assert",
"(",
"i",
">=",
"0",
")",
"assert",
"(",
"ibl",
">=",
"0",
")",
"if",
"isinstance",
"(",
"cls",
".",
"static_huffman_tree",
",",
"type",
"(",
"N... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | HPackZString.huffman_conv2str | huffman_conv2str converts a bitstring of bit_len bitlength into a
binary string. It DOES NOT compress/decompress the bitstring!
@param int bit_str: the bitstring to convert.
@param int bit_len: the bitlength of bit_str.
@return str: the converted bitstring as a bytestring.
@rais... | scapy/contrib/http2.py | def huffman_conv2str(cls, bit_str, bit_len):
# type: (int, int) -> str
""" huffman_conv2str converts a bitstring of bit_len bitlength into a
binary string. It DOES NOT compress/decompress the bitstring!
@param int bit_str: the bitstring to convert.
@param int bit_len: the bitlen... | def huffman_conv2str(cls, bit_str, bit_len):
# type: (int, int) -> str
""" huffman_conv2str converts a bitstring of bit_len bitlength into a
binary string. It DOES NOT compress/decompress the bitstring!
@param int bit_str: the bitstring to convert.
@param int bit_len: the bitlen... | [
"huffman_conv2str",
"converts",
"a",
"bitstring",
"of",
"bit_len",
"bitlength",
"into",
"a",
"binary",
"string",
".",
"It",
"DOES",
"NOT",
"compress",
"/",
"decompress",
"the",
"bitstring!"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L1111-L1137 | [
"def",
"huffman_conv2str",
"(",
"cls",
",",
"bit_str",
",",
"bit_len",
")",
":",
"# type: (int, int) -> str",
"assert",
"(",
"bit_str",
">=",
"0",
")",
"assert",
"(",
"bit_len",
">=",
"0",
")",
"byte_len",
"=",
"bit_len",
"//",
"8",
"rem_bit",
"=",
"bit_le... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | HPackZString.huffman_conv2bitstring | huffman_conv2bitstring converts a string into its bitstring
representation. It returns a tuple: the bitstring and its bitlength.
This function DOES NOT compress/decompress the string!
@param str s: the bytestring to convert.
@return (int, int): the bitstring of s, and its bitlength.
... | scapy/contrib/http2.py | def huffman_conv2bitstring(cls, s):
# type: (str) -> Tuple[int, int]
""" huffman_conv2bitstring converts a string into its bitstring
representation. It returns a tuple: the bitstring and its bitlength.
This function DOES NOT compress/decompress the string!
@param str s: the byte... | def huffman_conv2bitstring(cls, s):
# type: (str) -> Tuple[int, int]
""" huffman_conv2bitstring converts a string into its bitstring
representation. It returns a tuple: the bitstring and its bitlength.
This function DOES NOT compress/decompress the string!
@param str s: the byte... | [
"huffman_conv2bitstring",
"converts",
"a",
"string",
"into",
"its",
"bitstring",
"representation",
".",
"It",
"returns",
"a",
"tuple",
":",
"the",
"bitstring",
"and",
"its",
"bitlength",
".",
"This",
"function",
"DOES",
"NOT",
"compress",
"/",
"decompress",
"the... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L1140-L1158 | [
"def",
"huffman_conv2bitstring",
"(",
"cls",
",",
"s",
")",
":",
"# type: (str) -> Tuple[int, int]",
"i",
"=",
"0",
"ibl",
"=",
"len",
"(",
"s",
")",
"*",
"8",
"for",
"c",
"in",
"s",
":",
"i",
"=",
"(",
"i",
"<<",
"8",
")",
"+",
"orb",
"(",
"c",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | HPackZString.huffman_compute_decode_tree | huffman_compute_decode_tree initializes/builds the static_huffman_tree
@return None
@raise InvalidEncodingException if there is an encoding problem | scapy/contrib/http2.py | def huffman_compute_decode_tree(cls):
# type: () -> None
""" huffman_compute_decode_tree initializes/builds the static_huffman_tree
@return None
@raise InvalidEncodingException if there is an encoding problem
"""
cls.static_huffman_tree = HuffmanNode(None, None)
... | def huffman_compute_decode_tree(cls):
# type: () -> None
""" huffman_compute_decode_tree initializes/builds the static_huffman_tree
@return None
@raise InvalidEncodingException if there is an encoding problem
"""
cls.static_huffman_tree = HuffmanNode(None, None)
... | [
"huffman_compute_decode_tree",
"initializes",
"/",
"builds",
"the",
"static_huffman_tree"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L1161-L1181 | [
"def",
"huffman_compute_decode_tree",
"(",
"cls",
")",
":",
"# type: () -> None",
"cls",
".",
"static_huffman_tree",
"=",
"HuffmanNode",
"(",
"None",
",",
"None",
")",
"i",
"=",
"0",
"for",
"entry",
"in",
"cls",
".",
"static_huffman_code",
":",
"parent",
"=",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | HPackHdrString.self_build | self_build is overridden because type and len are determined at
build time, based on the "data" field internal type | scapy/contrib/http2.py | def self_build(self, field_pos_list=None):
# type: (Any) -> str
"""self_build is overridden because type and len are determined at
build time, based on the "data" field internal type
"""
if self.getfieldval('type') is None:
self.type = 1 if isinstance(self.getfieldval... | def self_build(self, field_pos_list=None):
# type: (Any) -> str
"""self_build is overridden because type and len are determined at
build time, based on the "data" field internal type
"""
if self.getfieldval('type') is None:
self.type = 1 if isinstance(self.getfieldval... | [
"self_build",
"is",
"overridden",
"because",
"type",
"and",
"len",
"are",
"determined",
"at",
"build",
"time",
"based",
"on",
"the",
"data",
"field",
"internal",
"type"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L1330-L1337 | [
"def",
"self_build",
"(",
"self",
",",
"field_pos_list",
"=",
"None",
")",
":",
"# type: (Any) -> str",
"if",
"self",
".",
"getfieldval",
"(",
"'type'",
")",
"is",
"None",
":",
"self",
".",
"type",
"=",
"1",
"if",
"isinstance",
"(",
"self",
".",
"getfiel... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | HPackHeaders.dispatch_hook | dispatch_hook returns the subclass of HPackHeaders that must be used
to dissect the string. | scapy/contrib/http2.py | def dispatch_hook(cls, s=None, *_args, **_kwds):
# type: (Optional[str], *Any, **Any) -> base_classes.Packet_metaclass
"""dispatch_hook returns the subclass of HPackHeaders that must be used
to dissect the string.
"""
if s is None:
return config.conf.raw_layer
... | def dispatch_hook(cls, s=None, *_args, **_kwds):
# type: (Optional[str], *Any, **Any) -> base_classes.Packet_metaclass
"""dispatch_hook returns the subclass of HPackHeaders that must be used
to dissect the string.
"""
if s is None:
return config.conf.raw_layer
... | [
"dispatch_hook",
"returns",
"the",
"subclass",
"of",
"HPackHeaders",
"that",
"must",
"be",
"used",
"to",
"dissect",
"the",
"string",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L1346-L1360 | [
"def",
"dispatch_hook",
"(",
"cls",
",",
"s",
"=",
"None",
",",
"*",
"_args",
",",
"*",
"*",
"_kwds",
")",
":",
"# type: (Optional[str], *Any, **Any) -> base_classes.Packet_metaclass",
"if",
"s",
"is",
"None",
":",
"return",
"config",
".",
"conf",
".",
"raw_la... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | H2PaddedDataFrame.get_data_len | get_data_len computes the length of the data field
To do this computation, the length of the padlen field and the actual
padding is subtracted to the string that was provided to the pre_dissect # noqa: E501
fun of the pkt parameter
@return int; length of the data part of the HTTP/2 fra... | scapy/contrib/http2.py | def get_data_len(self):
# type: () -> int
""" get_data_len computes the length of the data field
To do this computation, the length of the padlen field and the actual
padding is subtracted to the string that was provided to the pre_dissect # noqa: E501
fun of the pkt parameter
... | def get_data_len(self):
# type: () -> int
""" get_data_len computes the length of the data field
To do this computation, the length of the padlen field and the actual
padding is subtracted to the string that was provided to the pre_dissect # noqa: E501
fun of the pkt parameter
... | [
"get_data_len",
"computes",
"the",
"length",
"of",
"the",
"data",
"field"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L1469-L1485 | [
"def",
"get_data_len",
"(",
"self",
")",
":",
"# type: () -> int",
"padding_len",
"=",
"self",
".",
"getfieldval",
"(",
"'padlen'",
")",
"fld",
",",
"fval",
"=",
"self",
".",
"getfield_and_val",
"(",
"'padlen'",
")",
"padding_len_len",
"=",
"fld",
".",
"i2le... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | H2PaddedPriorityHeadersFrame.get_hdrs_len | get_hdrs_len computes the length of the hdrs field
To do this computation, the length of the padlen field, the priority
information fields and the actual padding is subtracted to the string
that was provided to the pre_dissect fun of the pkt parameter.
@return int: the length of the hdr... | scapy/contrib/http2.py | def get_hdrs_len(self):
# type: () -> int
""" get_hdrs_len computes the length of the hdrs field
To do this computation, the length of the padlen field, the priority
information fields and the actual padding is subtracted to the string
that was provided to the pre_dissect fun of... | def get_hdrs_len(self):
# type: () -> int
""" get_hdrs_len computes the length of the hdrs field
To do this computation, the length of the padlen field, the priority
information fields and the actual padding is subtracted to the string
that was provided to the pre_dissect fun of... | [
"get_hdrs_len",
"computes",
"the",
"length",
"of",
"the",
"hdrs",
"field"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L1619-L1644 | [
"def",
"get_hdrs_len",
"(",
"self",
")",
":",
"# type: () -> int",
"padding_len",
"=",
"self",
".",
"getfieldval",
"(",
"'padlen'",
")",
"fld",
",",
"fval",
"=",
"self",
".",
"getfield_and_val",
"(",
"'padlen'",
")",
"padding_len_len",
"=",
"fld",
".",
"i2le... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | H2PaddedPushPromiseFrame.get_hdrs_len | get_hdrs_len computes the length of the hdrs field
To do this computation, the length of the padlen field, reserved,
stream_id and the actual padding is subtracted to the string that was
provided to the pre_dissect fun of the pkt parameter.
@return int: the length of the hdrs field
... | scapy/contrib/http2.py | def get_hdrs_len(self):
# type: () -> int
""" get_hdrs_len computes the length of the hdrs field
To do this computation, the length of the padlen field, reserved,
stream_id and the actual padding is subtracted to the string that was
provided to the pre_dissect fun of the pkt par... | def get_hdrs_len(self):
# type: () -> int
""" get_hdrs_len computes the length of the hdrs field
To do this computation, the length of the padlen field, reserved,
stream_id and the actual padding is subtracted to the string that was
provided to the pre_dissect fun of the pkt par... | [
"get_hdrs_len",
"computes",
"the",
"length",
"of",
"the",
"hdrs",
"field"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L1834-L1855 | [
"def",
"get_hdrs_len",
"(",
"self",
")",
":",
"# type: () -> int",
"fld",
",",
"padding_len",
"=",
"self",
".",
"getfield_and_val",
"(",
"'padlen'",
")",
"padding_len_len",
"=",
"fld",
".",
"i2len",
"(",
"self",
",",
"padding_len",
")",
"bit_len",
"=",
"self... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | H2Frame.guess_payload_class | guess_payload_class returns the Class object to use for parsing a payload
This function uses the H2Frame.type field value to decide which payload to parse. The implement cannot be # noqa: E501
performed using the simple bind_layers helper because sometimes the selection of which Class object to return ... | scapy/contrib/http2.py | def guess_payload_class(self, payload):
# type: (str) -> base_classes.Packet_metaclass
""" guess_payload_class returns the Class object to use for parsing a payload
This function uses the H2Frame.type field value to decide which payload to parse. The implement cannot be # noqa: E501
per... | def guess_payload_class(self, payload):
# type: (str) -> base_classes.Packet_metaclass
""" guess_payload_class returns the Class object to use for parsing a payload
This function uses the H2Frame.type field value to decide which payload to parse. The implement cannot be # noqa: E501
per... | [
"guess_payload_class",
"returns",
"the",
"Class",
"object",
"to",
"use",
"for",
"parsing",
"a",
"payload",
"This",
"function",
"uses",
"the",
"H2Frame",
".",
"type",
"field",
"value",
"to",
"decide",
"which",
"payload",
"to",
"parse",
".",
"The",
"implement",
... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L1999-L2054 | [
"def",
"guess_payload_class",
"(",
"self",
",",
"payload",
")",
":",
"# type: (str) -> base_classes.Packet_metaclass",
"if",
"len",
"(",
"payload",
")",
"==",
"0",
":",
"return",
"packet",
".",
"NoPayload",
"t",
"=",
"self",
".",
"getfieldval",
"(",
"'type'",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | HPackHdrTable.resize | Resize the dynamic table. If the new size (ns) must be between 0 and
the cap size. If the new size is lower than the current size of the
dynamic table, entries are evicted.
@param int ns: the new size of the dynamic table
@raise AssertionError | scapy/contrib/http2.py | def resize(self, ns):
# type: (int) -> None
"""Resize the dynamic table. If the new size (ns) must be between 0 and
the cap size. If the new size is lower than the current size of the
dynamic table, entries are evicted.
@param int ns: the new size of the dynamic table
@ra... | def resize(self, ns):
# type: (int) -> None
"""Resize the dynamic table. If the new size (ns) must be between 0 and
the cap size. If the new size is lower than the current size of the
dynamic table, entries are evicted.
@param int ns: the new size of the dynamic table
@ra... | [
"Resize",
"the",
"dynamic",
"table",
".",
"If",
"the",
"new",
"size",
"(",
"ns",
")",
"must",
"be",
"between",
"0",
"and",
"the",
"cap",
"size",
".",
"If",
"the",
"new",
"size",
"is",
"lower",
"than",
"the",
"current",
"size",
"of",
"the",
"dynamic",... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L2312-L2326 | [
"def",
"resize",
"(",
"self",
",",
"ns",
")",
":",
"# type: (int) -> None",
"assert",
"0",
"<=",
"ns",
"<=",
"self",
".",
"_dynamic_table_cap_size",
",",
"'EINVAL: ns: out-of-range value; expected value is in the range [0;{}['",
".",
"format",
"(",
"self",
".",
"_dyna... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | HPackHdrTable.recap | recap changes the maximum size limit of the dynamic table. It also
proceeds to a resize(), if the new size is lower than the previous one.
@param int nc: the new cap of the dynamic table (that is the maximum-maximum size) # noqa: E501
@raise AssertionError | scapy/contrib/http2.py | def recap(self, nc):
# type: (int) -> None
"""recap changes the maximum size limit of the dynamic table. It also
proceeds to a resize(), if the new size is lower than the previous one.
@param int nc: the new cap of the dynamic table (that is the maximum-maximum size) # noqa: E501
... | def recap(self, nc):
# type: (int) -> None
"""recap changes the maximum size limit of the dynamic table. It also
proceeds to a resize(), if the new size is lower than the previous one.
@param int nc: the new cap of the dynamic table (that is the maximum-maximum size) # noqa: E501
... | [
"recap",
"changes",
"the",
"maximum",
"size",
"limit",
"of",
"the",
"dynamic",
"table",
".",
"It",
"also",
"proceeds",
"to",
"a",
"resize",
"()",
"if",
"the",
"new",
"size",
"is",
"lower",
"than",
"the",
"previous",
"one",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L2328-L2342 | [
"def",
"recap",
"(",
"self",
",",
"nc",
")",
":",
"# type: (int) -> None",
"assert",
"(",
"nc",
">=",
"0",
")",
"t",
"=",
"self",
".",
"_dynamic_table_cap_size",
">",
"nc",
"self",
".",
"_dynamic_table_cap_size",
"=",
"nc",
"if",
"t",
":",
"# The RFC is no... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | HPackHdrTable._reduce_dynamic_table | _reduce_dynamic_table evicts entries from the dynamic table until it
fits in less than the current size limit. The optional parameter,
new_entry_size, allows the resize to happen so that a new entry of this
size fits in.
@param int new_entry_size: if called before adding a new entry, the... | scapy/contrib/http2.py | def _reduce_dynamic_table(self, new_entry_size=0):
# type: (int) -> None
"""_reduce_dynamic_table evicts entries from the dynamic table until it
fits in less than the current size limit. The optional parameter,
new_entry_size, allows the resize to happen so that a new entry of this
... | def _reduce_dynamic_table(self, new_entry_size=0):
# type: (int) -> None
"""_reduce_dynamic_table evicts entries from the dynamic table until it
fits in less than the current size limit. The optional parameter,
new_entry_size, allows the resize to happen so that a new entry of this
... | [
"_reduce_dynamic_table",
"evicts",
"entries",
"from",
"the",
"dynamic",
"table",
"until",
"it",
"fits",
"in",
"less",
"than",
"the",
"current",
"size",
"limit",
".",
"The",
"optional",
"parameter",
"new_entry_size",
"allows",
"the",
"resize",
"to",
"happen",
"so... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L2344-L2361 | [
"def",
"_reduce_dynamic_table",
"(",
"self",
",",
"new_entry_size",
"=",
"0",
")",
":",
"# type: (int) -> None",
"assert",
"(",
"new_entry_size",
">=",
"0",
")",
"cur_sz",
"=",
"len",
"(",
"self",
")",
"dyn_tbl_sz",
"=",
"len",
"(",
"self",
".",
"_dynamic_ta... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | HPackHdrTable.register | register adds to this table the instances of
HPackLitHdrFldWithIncrIndexing provided as parameters.
A H2Frame with a H2HeadersFrame payload can be provided, as much as a
python list of HPackHeaders or a single HPackLitHdrFldWithIncrIndexing
instance.
@param HPackLitHdrFldWithInc... | scapy/contrib/http2.py | def register(self, hdrs):
# type: (Union[HPackLitHdrFldWithIncrIndexing, H2Frame, List[HPackHeaders]]) -> None # noqa: E501
"""register adds to this table the instances of
HPackLitHdrFldWithIncrIndexing provided as parameters.
A H2Frame with a H2HeadersFrame payload can be provided, as... | def register(self, hdrs):
# type: (Union[HPackLitHdrFldWithIncrIndexing, H2Frame, List[HPackHeaders]]) -> None # noqa: E501
"""register adds to this table the instances of
HPackLitHdrFldWithIncrIndexing provided as parameters.
A H2Frame with a H2HeadersFrame payload can be provided, as... | [
"register",
"adds",
"to",
"this",
"table",
"the",
"instances",
"of",
"HPackLitHdrFldWithIncrIndexing",
"provided",
"as",
"parameters",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L2363-L2407 | [
"def",
"register",
"(",
"self",
",",
"hdrs",
")",
":",
"# type: (Union[HPackLitHdrFldWithIncrIndexing, H2Frame, List[HPackHeaders]]) -> None # noqa: E501",
"if",
"isinstance",
"(",
"hdrs",
",",
"H2Frame",
")",
":",
"hdrs",
"=",
"[",
"hdr",
"for",
"hdr",
"in",
"hdrs",... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | HPackHdrTable.get_idx_by_name | get_idx_by_name returns the index of a matching registered header
This implementation will prefer returning a static entry index whenever
possible. If multiple matching header name are found in the static
table, there is insurance that the first entry (lowest index number)
will be retur... | scapy/contrib/http2.py | def get_idx_by_name(self, name):
# type: (str) -> Optional[int]
""" get_idx_by_name returns the index of a matching registered header
This implementation will prefer returning a static entry index whenever
possible. If multiple matching header name are found in the static
table,... | def get_idx_by_name(self, name):
# type: (str) -> Optional[int]
""" get_idx_by_name returns the index of a matching registered header
This implementation will prefer returning a static entry index whenever
possible. If multiple matching header name are found in the static
table,... | [
"get_idx_by_name",
"returns",
"the",
"index",
"of",
"a",
"matching",
"registered",
"header"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L2409-L2426 | [
"def",
"get_idx_by_name",
"(",
"self",
",",
"name",
")",
":",
"# type: (str) -> Optional[int]",
"name",
"=",
"name",
".",
"lower",
"(",
")",
"for",
"key",
",",
"val",
"in",
"six",
".",
"iteritems",
"(",
"type",
"(",
"self",
")",
".",
"_static_entries",
"... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | HPackHdrTable.gen_txt_repr | gen_txt_repr returns a "textual" representation of the provided
headers.
The output of this function is compatible with the input of
parse_txt_hdrs.
@param H2Frame|list of HPackHeaders hdrs: the list of headers to convert to textual representation # noqa: E501
@param bool: whet... | scapy/contrib/http2.py | def gen_txt_repr(self, hdrs, register=True):
# type: (Union[H2Frame, List[HPackHeaders]], Optional[bool]) -> str
""" gen_txt_repr returns a "textual" representation of the provided
headers.
The output of this function is compatible with the input of
parse_txt_hdrs.
@para... | def gen_txt_repr(self, hdrs, register=True):
# type: (Union[H2Frame, List[HPackHeaders]], Optional[bool]) -> str
""" gen_txt_repr returns a "textual" representation of the provided
headers.
The output of this function is compatible with the input of
parse_txt_hdrs.
@para... | [
"gen_txt_repr",
"returns",
"a",
"textual",
"representation",
"of",
"the",
"provided",
"headers",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L2453-L2501 | [
"def",
"gen_txt_repr",
"(",
"self",
",",
"hdrs",
",",
"register",
"=",
"True",
")",
":",
"# type: (Union[H2Frame, List[HPackHeaders]], Optional[bool]) -> str",
"lst",
"=",
"[",
"]",
"if",
"isinstance",
"(",
"hdrs",
",",
"H2Frame",
")",
":",
"hdrs",
"=",
"hdrs",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | HPackHdrTable._convert_a_header_to_a_h2_header | _convert_a_header_to_a_h2_header builds a HPackHeaders from a header
name and a value. It returns a HPackIndexedHdr whenever possible. If not, # noqa: E501
it returns a HPackLitHdrFldWithoutIndexing or a
HPackLitHdrFldWithIncrIndexing, based on the should_index callback.
HPackLitHdrFldW... | scapy/contrib/http2.py | def _convert_a_header_to_a_h2_header(self, hdr_name, hdr_value, is_sensitive, should_index): # noqa: E501
# type: (str, str, Callable[[str, str], bool], Callable[[str], bool]) -> Tuple[HPackHeaders, int] # noqa: E501
""" _convert_a_header_to_a_h2_header builds a HPackHeaders from a header
name... | def _convert_a_header_to_a_h2_header(self, hdr_name, hdr_value, is_sensitive, should_index): # noqa: E501
# type: (str, str, Callable[[str, str], bool], Callable[[str], bool]) -> Tuple[HPackHeaders, int] # noqa: E501
""" _convert_a_header_to_a_h2_header builds a HPackHeaders from a header
name... | [
"_convert_a_header_to_a_h2_header",
"builds",
"a",
"HPackHeaders",
"from",
"a",
"header",
"name",
"and",
"a",
"value",
".",
"It",
"returns",
"a",
"HPackIndexedHdr",
"whenever",
"possible",
".",
"If",
"not",
"#",
"noqa",
":",
"E501",
"it",
"returns",
"a",
"HPac... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L2512-L2605 | [
"def",
"_convert_a_header_to_a_h2_header",
"(",
"self",
",",
"hdr_name",
",",
"hdr_value",
",",
"is_sensitive",
",",
"should_index",
")",
":",
"# noqa: E501",
"# type: (str, str, Callable[[str, str], bool], Callable[[str], bool]) -> Tuple[HPackHeaders, int] # noqa: E501",
"# If both... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | HPackHdrTable.parse_txt_hdrs | parse_txt_hdrs parses headers expressed in text and converts them
into a series of H2Frames with the "correct" flags. A body can be provided # noqa: E501
in which case, the data frames are added, bearing the End Stream flag,
instead of the H2HeadersFrame/H2ContinuationFrame. The generated frame... | scapy/contrib/http2.py | def parse_txt_hdrs(self,
s, # type: str
stream_id=1, # type: int
body=None, # type: Optional[str]
max_frm_sz=4096, # type: int
max_hdr_lst_sz=0, # type: int
is_sensitive=lambda ... | def parse_txt_hdrs(self,
s, # type: str
stream_id=1, # type: int
body=None, # type: Optional[str]
max_frm_sz=4096, # type: int
max_hdr_lst_sz=0, # type: int
is_sensitive=lambda ... | [
"parse_txt_hdrs",
"parses",
"headers",
"expressed",
"in",
"text",
"and",
"converts",
"them",
"into",
"a",
"series",
"of",
"H2Frames",
"with",
"the",
"correct",
"flags",
".",
"A",
"body",
"can",
"be",
"provided",
"#",
"noqa",
":",
"E501",
"in",
"which",
"ca... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/http2.py#L2625-L2730 | [
"def",
"parse_txt_hdrs",
"(",
"self",
",",
"s",
",",
"# type: str",
"stream_id",
"=",
"1",
",",
"# type: int",
"body",
"=",
"None",
",",
"# type: Optional[str]",
"max_frm_sz",
"=",
"4096",
",",
"# type: int",
"max_hdr_lst_sz",
"=",
"0",
",",
"# type: int",
"is... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | AVP | Craft an AVP based on its id and optional parameter fields | scapy/contrib/diameter.py | def AVP(avpId, **fields):
""" Craft an AVP based on its id and optional parameter fields"""
val = None
classType = AVP_Unknown
if isinstance(avpId, str):
try:
for vnd in AvpDefDict:
for code in AvpDefDict[vnd]:
val = AvpDefDict[vnd][code]
... | def AVP(avpId, **fields):
""" Craft an AVP based on its id and optional parameter fields"""
val = None
classType = AVP_Unknown
if isinstance(avpId, str):
try:
for vnd in AvpDefDict:
for code in AvpDefDict[vnd]:
val = AvpDefDict[vnd][code]
... | [
"Craft",
"an",
"AVP",
"based",
"on",
"its",
"id",
"and",
"optional",
"parameter",
"fields"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/diameter.py#L391-L440 | [
"def",
"AVP",
"(",
"avpId",
",",
"*",
"*",
"fields",
")",
":",
"val",
"=",
"None",
"classType",
"=",
"AVP_Unknown",
"if",
"isinstance",
"(",
"avpId",
",",
"str",
")",
":",
"try",
":",
"for",
"vnd",
"in",
"AvpDefDict",
":",
"for",
"code",
"in",
"Avp... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | getCmdParams | Update or fill the fields parameters depending on command code. Both cmd and drAppId can be provided # noqa: E501
in string or int format. | scapy/contrib/diameter.py | def getCmdParams(cmd, request, **fields):
"""Update or fill the fields parameters depending on command code. Both cmd and drAppId can be provided # noqa: E501
in string or int format."""
drCode = None
params = None
drAppId = None
# Fetch the parameters if cmd is found in dict
if isinstan... | def getCmdParams(cmd, request, **fields):
"""Update or fill the fields parameters depending on command code. Both cmd and drAppId can be provided # noqa: E501
in string or int format."""
drCode = None
params = None
drAppId = None
# Fetch the parameters if cmd is found in dict
if isinstan... | [
"Update",
"or",
"fill",
"the",
"fields",
"parameters",
"depending",
"on",
"command",
"code",
".",
"Both",
"cmd",
"and",
"drAppId",
"can",
"be",
"provided",
"#",
"noqa",
":",
"E501",
"in",
"string",
"or",
"int",
"format",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/diameter.py#L4744-L4808 | [
"def",
"getCmdParams",
"(",
"cmd",
",",
"request",
",",
"*",
"*",
"fields",
")",
":",
"drCode",
"=",
"None",
"params",
"=",
"None",
"drAppId",
"=",
"None",
"# Fetch the parameters if cmd is found in dict",
"if",
"isinstance",
"(",
"cmd",
",",
"int",
")",
":"... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | DiamReq | Craft Diameter request commands | scapy/contrib/diameter.py | def DiamReq(cmd, **fields):
"""Craft Diameter request commands"""
upfields, name = getCmdParams(cmd, True, **fields)
p = DiamG(**upfields)
p.name = name
return p | def DiamReq(cmd, **fields):
"""Craft Diameter request commands"""
upfields, name = getCmdParams(cmd, True, **fields)
p = DiamG(**upfields)
p.name = name
return p | [
"Craft",
"Diameter",
"request",
"commands"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/diameter.py#L4811-L4816 | [
"def",
"DiamReq",
"(",
"cmd",
",",
"*",
"*",
"fields",
")",
":",
"upfields",
",",
"name",
"=",
"getCmdParams",
"(",
"cmd",
",",
"True",
",",
"*",
"*",
"fields",
")",
"p",
"=",
"DiamG",
"(",
"*",
"*",
"upfields",
")",
"p",
".",
"name",
"=",
"nam... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | DiamAns | Craft Diameter answer commands | scapy/contrib/diameter.py | def DiamAns(cmd, **fields):
"""Craft Diameter answer commands"""
upfields, name = getCmdParams(cmd, False, **fields)
p = DiamG(**upfields)
p.name = name
return p | def DiamAns(cmd, **fields):
"""Craft Diameter answer commands"""
upfields, name = getCmdParams(cmd, False, **fields)
p = DiamG(**upfields)
p.name = name
return p | [
"Craft",
"Diameter",
"answer",
"commands"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/diameter.py#L4819-L4824 | [
"def",
"DiamAns",
"(",
"cmd",
",",
"*",
"*",
"fields",
")",
":",
"upfields",
",",
"name",
"=",
"getCmdParams",
"(",
"cmd",
",",
"False",
",",
"*",
"*",
"fields",
")",
"p",
"=",
"DiamG",
"(",
"*",
"*",
"upfields",
")",
"p",
".",
"name",
"=",
"na... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | Field.i2m | Convert internal value to machine value | scapy/fields.py | def i2m(self, pkt, x):
"""Convert internal value to machine value"""
if x is None:
x = 0
elif isinstance(x, str):
return bytes_encode(x)
return x | def i2m(self, pkt, x):
"""Convert internal value to machine value"""
if x is None:
x = 0
elif isinstance(x, str):
return bytes_encode(x)
return x | [
"Convert",
"internal",
"value",
"to",
"machine",
"value"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/fields.py#L117-L123 | [
"def",
"i2m",
"(",
"self",
",",
"pkt",
",",
"x",
")",
":",
"if",
"x",
"is",
"None",
":",
"x",
"=",
"0",
"elif",
"isinstance",
"(",
"x",
",",
"str",
")",
":",
"return",
"bytes_encode",
"(",
"x",
")",
"return",
"x"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | MultipleTypeField._iterate_fields_cond | Internal function used by _find_fld_pkt & _find_fld_pkt_val | scapy/fields.py | def _iterate_fields_cond(self, pkt, val, use_val):
"""Internal function used by _find_fld_pkt & _find_fld_pkt_val"""
# Iterate through the fields
for fld, cond in self.flds:
if isinstance(cond, tuple):
if use_val:
if cond[1](pkt, val):
... | def _iterate_fields_cond(self, pkt, val, use_val):
"""Internal function used by _find_fld_pkt & _find_fld_pkt_val"""
# Iterate through the fields
for fld, cond in self.flds:
if isinstance(cond, tuple):
if use_val:
if cond[1](pkt, val):
... | [
"Internal",
"function",
"used",
"by",
"_find_fld_pkt",
"&",
"_find_fld_pkt_val"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/fields.py#L278-L291 | [
"def",
"_iterate_fields_cond",
"(",
"self",
",",
"pkt",
",",
"val",
",",
"use_val",
")",
":",
"# Iterate through the fields",
"for",
"fld",
",",
"cond",
"in",
"self",
".",
"flds",
":",
"if",
"isinstance",
"(",
"cond",
",",
"tuple",
")",
":",
"if",
"use_v... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | MultipleTypeField._find_fld_pkt_val | Given a Packet instance `pkt` and the value `val` to be set,
returns the Field subclass to be used, and the updated `val` if necessary. | scapy/fields.py | def _find_fld_pkt_val(self, pkt, val):
"""Given a Packet instance `pkt` and the value `val` to be set,
returns the Field subclass to be used, and the updated `val` if necessary.
"""
fld = self._iterate_fields_cond(pkt, val, True)
# Default ? (in this case, let's make sure it's up-do-dat... | def _find_fld_pkt_val(self, pkt, val):
"""Given a Packet instance `pkt` and the value `val` to be set,
returns the Field subclass to be used, and the updated `val` if necessary.
"""
fld = self._iterate_fields_cond(pkt, val, True)
# Default ? (in this case, let's make sure it's up-do-dat... | [
"Given",
"a",
"Packet",
"instance",
"pkt",
"and",
"the",
"value",
"val",
"to",
"be",
"set",
"returns",
"the",
"Field",
"subclass",
"to",
"be",
"used",
"and",
"the",
"updated",
"val",
"if",
"necessary",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/fields.py#L301-L312 | [
"def",
"_find_fld_pkt_val",
"(",
"self",
",",
"pkt",
",",
"val",
")",
":",
"fld",
"=",
"self",
".",
"_iterate_fields_cond",
"(",
"pkt",
",",
"val",
",",
"True",
")",
"# Default ? (in this case, let's make sure it's up-do-date)",
"dflts_pkt",
"=",
"pkt",
".",
"de... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | MultipleTypeField._find_fld | Returns the Field subclass to be used, depending on the Packet
instance, or the default subclass.
DEV: since the Packet instance is not provided, we have to use a hack
to guess it. It should only be used if you cannot provide the current
Packet instance (for example, because of the current Scapy API).
If you have the... | scapy/fields.py | def _find_fld(self):
"""Returns the Field subclass to be used, depending on the Packet
instance, or the default subclass.
DEV: since the Packet instance is not provided, we have to use a hack
to guess it. It should only be used if you cannot provide the current
Packet instance (for example, because of the curr... | def _find_fld(self):
"""Returns the Field subclass to be used, depending on the Packet
instance, or the default subclass.
DEV: since the Packet instance is not provided, we have to use a hack
to guess it. It should only be used if you cannot provide the current
Packet instance (for example, because of the curr... | [
"Returns",
"the",
"Field",
"subclass",
"to",
"be",
"used",
"depending",
"on",
"the",
"Packet",
"instance",
"or",
"the",
"default",
"subclass",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/fields.py#L314-L338 | [
"def",
"_find_fld",
"(",
"self",
")",
":",
"# Hack to preserve current Scapy API",
"# See https://stackoverflow.com/a/7272464/3223422",
"frame",
"=",
"inspect",
".",
"currentframe",
"(",
")",
".",
"f_back",
".",
"f_back",
"while",
"frame",
"is",
"not",
"None",
":",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | FlagsField._fixup_val | Returns a FlagValue instance when needed. Internal method, to be
used in *2i() and i2*() methods. | scapy/fields.py | def _fixup_val(self, x):
"""Returns a FlagValue instance when needed. Internal method, to be
used in *2i() and i2*() methods.
"""
if isinstance(x, (list, tuple)):
return type(x)(
v if v is None or isinstance(v, FlagValue)
else FlagValue(v, self.names)... | def _fixup_val(self, x):
"""Returns a FlagValue instance when needed. Internal method, to be
used in *2i() and i2*() methods.
"""
if isinstance(x, (list, tuple)):
return type(x)(
v if v is None or isinstance(v, FlagValue)
else FlagValue(v, self.names)... | [
"Returns",
"a",
"FlagValue",
"instance",
"when",
"needed",
".",
"Internal",
"method",
"to",
"be",
"used",
"in",
"*",
"2i",
"()",
"and",
"i2",
"*",
"()",
"methods",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/fields.py#L1965-L1976 | [
"def",
"_fixup_val",
"(",
"self",
",",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"return",
"type",
"(",
"x",
")",
"(",
"v",
"if",
"v",
"is",
"None",
"or",
"isinstance",
"(",
"v",
",",
"FlagValue... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | UUIDField._check_uuid_fmt | Checks .uuid_fmt, and raises an exception if it is not valid. | scapy/fields.py | def _check_uuid_fmt(self):
"""Checks .uuid_fmt, and raises an exception if it is not valid."""
if self.uuid_fmt not in UUIDField.FORMATS:
raise FieldValueRangeException(
"Unsupported uuid_fmt ({})".format(self.uuid_fmt)) | def _check_uuid_fmt(self):
"""Checks .uuid_fmt, and raises an exception if it is not valid."""
if self.uuid_fmt not in UUIDField.FORMATS:
raise FieldValueRangeException(
"Unsupported uuid_fmt ({})".format(self.uuid_fmt)) | [
"Checks",
".",
"uuid_fmt",
"and",
"raises",
"an",
"exception",
"if",
"it",
"is",
"not",
"valid",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/fields.py#L2392-L2396 | [
"def",
"_check_uuid_fmt",
"(",
"self",
")",
":",
"if",
"self",
".",
"uuid_fmt",
"not",
"in",
"UUIDField",
".",
"FORMATS",
":",
"raise",
"FieldValueRangeException",
"(",
"\"Unsupported uuid_fmt ({})\"",
".",
"format",
"(",
"self",
".",
"uuid_fmt",
")",
")"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | TLSInnerPlaintext.pre_dissect | We need to parse the padding and type as soon as possible,
else we won't be able to parse the message list... | scapy/layers/tls/record_tls13.py | def pre_dissect(self, s):
"""
We need to parse the padding and type as soon as possible,
else we won't be able to parse the message list...
"""
if len(s) < 1:
raise Exception("Invalid InnerPlaintext (too short).")
tmp_len = len(s) - 1
if s[-1] != b"\x... | def pre_dissect(self, s):
"""
We need to parse the padding and type as soon as possible,
else we won't be able to parse the message list...
"""
if len(s) < 1:
raise Exception("Invalid InnerPlaintext (too short).")
tmp_len = len(s) - 1
if s[-1] != b"\x... | [
"We",
"need",
"to",
"parse",
"the",
"padding",
"and",
"type",
"as",
"soon",
"as",
"possible",
"else",
"we",
"won",
"t",
"be",
"able",
"to",
"parse",
"the",
"message",
"list",
"..."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record_tls13.py#L39-L59 | [
"def",
"pre_dissect",
"(",
"self",
",",
"s",
")",
":",
"if",
"len",
"(",
"s",
")",
"<",
"1",
":",
"raise",
"Exception",
"(",
"\"Invalid InnerPlaintext (too short).\"",
")",
"tmp_len",
"=",
"len",
"(",
"s",
")",
"-",
"1",
"if",
"s",
"[",
"-",
"1",
"... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | TLS13._tls_auth_decrypt | Provided with the record header and AEAD-ciphered data, return the
sliced and clear tuple (TLSInnerPlaintext, tag). Note that
we still return the slicing of the original input in case of decryption
failure. Also, if the integrity check fails, a warning will be issued,
but we still return... | scapy/layers/tls/record_tls13.py | def _tls_auth_decrypt(self, s):
"""
Provided with the record header and AEAD-ciphered data, return the
sliced and clear tuple (TLSInnerPlaintext, tag). Note that
we still return the slicing of the original input in case of decryption
failure. Also, if the integrity check fails, a... | def _tls_auth_decrypt(self, s):
"""
Provided with the record header and AEAD-ciphered data, return the
sliced and clear tuple (TLSInnerPlaintext, tag). Note that
we still return the slicing of the original input in case of decryption
failure. Also, if the integrity check fails, a... | [
"Provided",
"with",
"the",
"record",
"header",
"and",
"AEAD",
"-",
"ciphered",
"data",
"return",
"the",
"sliced",
"and",
"clear",
"tuple",
"(",
"TLSInnerPlaintext",
"tag",
")",
".",
"Note",
"that",
"we",
"still",
"return",
"the",
"slicing",
"of",
"the",
"o... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record_tls13.py#L104-L122 | [
"def",
"_tls_auth_decrypt",
"(",
"self",
",",
"s",
")",
":",
"rcs",
"=",
"self",
".",
"tls_session",
".",
"rcs",
"read_seq_num",
"=",
"struct",
".",
"pack",
"(",
"\"!Q\"",
",",
"rcs",
".",
"seq_num",
")",
"rcs",
".",
"seq_num",
"+=",
"1",
"try",
":",... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | TLS13.pre_dissect | Decrypt, verify and decompress the message. | scapy/layers/tls/record_tls13.py | def pre_dissect(self, s):
"""
Decrypt, verify and decompress the message.
"""
if len(s) < 5:
raise Exception("Invalid record: header is too short.")
if isinstance(self.tls_session.rcs.cipher, Cipher_NULL):
self.deciphered_len = None
return s
... | def pre_dissect(self, s):
"""
Decrypt, verify and decompress the message.
"""
if len(s) < 5:
raise Exception("Invalid record: header is too short.")
if isinstance(self.tls_session.rcs.cipher, Cipher_NULL):
self.deciphered_len = None
return s
... | [
"Decrypt",
"verify",
"and",
"decompress",
"the",
"message",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record_tls13.py#L124-L139 | [
"def",
"pre_dissect",
"(",
"self",
",",
"s",
")",
":",
"if",
"len",
"(",
"s",
")",
"<",
"5",
":",
"raise",
"Exception",
"(",
"\"Invalid record: header is too short.\"",
")",
"if",
"isinstance",
"(",
"self",
".",
"tls_session",
".",
"rcs",
".",
"cipher",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | TLS13.post_dissect | Commit the pending read state if it has been triggered. We update
nothing if the prcs was not set, as this probably means that we're
working out-of-context (and we need to keep the default rcs). | scapy/layers/tls/record_tls13.py | def post_dissect(self, s):
"""
Commit the pending read state if it has been triggered. We update
nothing if the prcs was not set, as this probably means that we're
working out-of-context (and we need to keep the default rcs).
"""
if self.tls_session.triggered_prcs_commit:... | def post_dissect(self, s):
"""
Commit the pending read state if it has been triggered. We update
nothing if the prcs was not set, as this probably means that we're
working out-of-context (and we need to keep the default rcs).
"""
if self.tls_session.triggered_prcs_commit:... | [
"Commit",
"the",
"pending",
"read",
"state",
"if",
"it",
"has",
"been",
"triggered",
".",
"We",
"update",
"nothing",
"if",
"the",
"prcs",
"was",
"not",
"set",
"as",
"this",
"probably",
"means",
"that",
"we",
"re",
"working",
"out",
"-",
"of",
"-",
"con... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record_tls13.py#L141-L152 | [
"def",
"post_dissect",
"(",
"self",
",",
"s",
")",
":",
"if",
"self",
".",
"tls_session",
".",
"triggered_prcs_commit",
":",
"if",
"self",
".",
"tls_session",
".",
"prcs",
"is",
"not",
"None",
":",
"self",
".",
"tls_session",
".",
"rcs",
"=",
"self",
"... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | TLS13._tls_auth_encrypt | Return the TLSCiphertext.encrypted_record for AEAD ciphers. | scapy/layers/tls/record_tls13.py | def _tls_auth_encrypt(self, s):
"""
Return the TLSCiphertext.encrypted_record for AEAD ciphers.
"""
wcs = self.tls_session.wcs
write_seq_num = struct.pack("!Q", wcs.seq_num)
wcs.seq_num += 1
return wcs.cipher.auth_encrypt(s, b"", write_seq_num) | def _tls_auth_encrypt(self, s):
"""
Return the TLSCiphertext.encrypted_record for AEAD ciphers.
"""
wcs = self.tls_session.wcs
write_seq_num = struct.pack("!Q", wcs.seq_num)
wcs.seq_num += 1
return wcs.cipher.auth_encrypt(s, b"", write_seq_num) | [
"Return",
"the",
"TLSCiphertext",
".",
"encrypted_record",
"for",
"AEAD",
"ciphers",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record_tls13.py#L172-L179 | [
"def",
"_tls_auth_encrypt",
"(",
"self",
",",
"s",
")",
":",
"wcs",
"=",
"self",
".",
"tls_session",
".",
"wcs",
"write_seq_num",
"=",
"struct",
".",
"pack",
"(",
"\"!Q\"",
",",
"wcs",
".",
"seq_num",
")",
"wcs",
".",
"seq_num",
"+=",
"1",
"return",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | TLS13.post_build | Apply the previous methods according to the writing cipher type. | scapy/layers/tls/record_tls13.py | def post_build(self, pkt, pay):
"""
Apply the previous methods according to the writing cipher type.
"""
# Compute the length of TLSPlaintext fragment
hdr, frag = pkt[:5], pkt[5:]
if not isinstance(self.tls_session.rcs.cipher, Cipher_NULL):
frag = self._tls_au... | def post_build(self, pkt, pay):
"""
Apply the previous methods according to the writing cipher type.
"""
# Compute the length of TLSPlaintext fragment
hdr, frag = pkt[:5], pkt[5:]
if not isinstance(self.tls_session.rcs.cipher, Cipher_NULL):
frag = self._tls_au... | [
"Apply",
"the",
"previous",
"methods",
"according",
"to",
"the",
"writing",
"cipher",
"type",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/record_tls13.py#L181-L206 | [
"def",
"post_build",
"(",
"self",
",",
"pkt",
",",
"pay",
")",
":",
"# Compute the length of TLSPlaintext fragment",
"hdr",
",",
"frag",
"=",
"pkt",
"[",
":",
"5",
"]",
",",
"pkt",
"[",
"5",
":",
"]",
"if",
"not",
"isinstance",
"(",
"self",
".",
"tls_s... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | ARC4_encrypt | Encrypt data @data with key @key, skipping @skip first bytes of the
keystream | scapy/modules/krack/crypto.py | def ARC4_encrypt(key, data, skip=0):
"""Encrypt data @data with key @key, skipping @skip first bytes of the
keystream"""
algorithm = algorithms.ARC4(key)
cipher = Cipher(algorithm, mode=None, backend=default_backend())
encryptor = cipher.encryptor()
if skip:
encryptor.update(b"\x00" * s... | def ARC4_encrypt(key, data, skip=0):
"""Encrypt data @data with key @key, skipping @skip first bytes of the
keystream"""
algorithm = algorithms.ARC4(key)
cipher = Cipher(algorithm, mode=None, backend=default_backend())
encryptor = cipher.encryptor()
if skip:
encryptor.update(b"\x00" * s... | [
"Encrypt",
"data"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/modules/krack/crypto.py#L18-L27 | [
"def",
"ARC4_encrypt",
"(",
"key",
",",
"data",
",",
"skip",
"=",
"0",
")",
":",
"algorithm",
"=",
"algorithms",
".",
"ARC4",
"(",
"key",
")",
"cipher",
"=",
"Cipher",
"(",
"algorithm",
",",
"mode",
"=",
"None",
",",
"backend",
"=",
"default_backend",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | customPRF512 | Source https://stackoverflow.com/questions/12018920/ | scapy/modules/krack/crypto.py | def customPRF512(key, amac, smac, anonce, snonce):
"""Source https://stackoverflow.com/questions/12018920/"""
A = b"Pairwise key expansion"
B = b"".join(sorted([amac, smac]) + sorted([anonce, snonce]))
blen = 64
i = 0
R = b''
while i <= ((blen * 8 + 159) / 160):
hmacsha1 = hmac.new(... | def customPRF512(key, amac, smac, anonce, snonce):
"""Source https://stackoverflow.com/questions/12018920/"""
A = b"Pairwise key expansion"
B = b"".join(sorted([amac, smac]) + sorted([anonce, snonce]))
blen = 64
i = 0
R = b''
while i <= ((blen * 8 + 159) / 160):
hmacsha1 = hmac.new(... | [
"Source",
"https",
":",
"//",
"stackoverflow",
".",
"com",
"/",
"questions",
"/",
"12018920",
"/"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/modules/krack/crypto.py#L38-L50 | [
"def",
"customPRF512",
"(",
"key",
",",
"amac",
",",
"smac",
",",
"anonce",
",",
"snonce",
")",
":",
"A",
"=",
"b\"Pairwise key expansion\"",
"B",
"=",
"b\"\"",
".",
"join",
"(",
"sorted",
"(",
"[",
"amac",
",",
"smac",
"]",
")",
"+",
"sorted",
"(",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | gen_TKIP_RC4_key | Implement TKIP WEPSeed generation
TSC: packet IV
TA: target addr bytes
TK: temporal key | scapy/modules/krack/crypto.py | def gen_TKIP_RC4_key(TSC, TA, TK):
"""Implement TKIP WEPSeed generation
TSC: packet IV
TA: target addr bytes
TK: temporal key
"""
assert len(TSC) == 6
assert len(TA) == 6
assert len(TK) == 16
assert all(isinstance(x, six.integer_types) for x in TSC + TA + TK)
# Phase 1
# 80... | def gen_TKIP_RC4_key(TSC, TA, TK):
"""Implement TKIP WEPSeed generation
TSC: packet IV
TA: target addr bytes
TK: temporal key
"""
assert len(TSC) == 6
assert len(TA) == 6
assert len(TK) == 16
assert all(isinstance(x, six.integer_types) for x in TSC + TA + TK)
# Phase 1
# 80... | [
"Implement",
"TKIP",
"WEPSeed",
"generation",
"TSC",
":",
"packet",
"IV",
"TA",
":",
"target",
"addr",
"bytes",
"TK",
":",
"temporal",
"key"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/modules/krack/crypto.py#L148-L214 | [
"def",
"gen_TKIP_RC4_key",
"(",
"TSC",
",",
"TA",
",",
"TK",
")",
":",
"assert",
"len",
"(",
"TSC",
")",
"==",
"6",
"assert",
"len",
"(",
"TA",
")",
"==",
"6",
"assert",
"len",
"(",
"TK",
")",
"==",
"16",
"assert",
"all",
"(",
"isinstance",
"(",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | _michael_b | Defined in 802.11i p.49 | scapy/modules/krack/crypto.py | def _michael_b(m_l, m_r):
"""Defined in 802.11i p.49"""
m_r = m_r ^ _rotate_left32(m_l, 17)
m_l = (m_l + m_r) % 2**32
m_r = m_r ^ _XSWAP(m_l)
m_l = (m_l + m_r) % 2**32
m_r = m_r ^ _rotate_left32(m_l, 3)
m_l = (m_l + m_r) % 2**32
m_r = m_r ^ _rotate_right32(m_l, 2)
m_l = (m_l + m_r) %... | def _michael_b(m_l, m_r):
"""Defined in 802.11i p.49"""
m_r = m_r ^ _rotate_left32(m_l, 17)
m_l = (m_l + m_r) % 2**32
m_r = m_r ^ _XSWAP(m_l)
m_l = (m_l + m_r) % 2**32
m_r = m_r ^ _rotate_left32(m_l, 3)
m_l = (m_l + m_r) % 2**32
m_r = m_r ^ _rotate_right32(m_l, 2)
m_l = (m_l + m_r) %... | [
"Defined",
"in",
"802",
".",
"11i",
"p",
".",
"49"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/modules/krack/crypto.py#L233-L243 | [
"def",
"_michael_b",
"(",
"m_l",
",",
"m_r",
")",
":",
"m_r",
"=",
"m_r",
"^",
"_rotate_left32",
"(",
"m_l",
",",
"17",
")",
"m_l",
"=",
"(",
"m_l",
"+",
"m_r",
")",
"%",
"2",
"**",
"32",
"m_r",
"=",
"m_r",
"^",
"_XSWAP",
"(",
"m_l",
")",
"m_... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | michael | Defined in 802.11i p.48 | scapy/modules/krack/crypto.py | def michael(key, to_hash):
"""Defined in 802.11i p.48"""
# Block size: 4
nb_block, nb_extra_bytes = divmod(len(to_hash), 4)
# Add padding
data = to_hash + chb(0x5a) + b"\x00" * (7 - nb_extra_bytes)
# Hash
m_l, m_r = unpack('<II', key)
for i in range(nb_block + 2):
# Convert i-t... | def michael(key, to_hash):
"""Defined in 802.11i p.48"""
# Block size: 4
nb_block, nb_extra_bytes = divmod(len(to_hash), 4)
# Add padding
data = to_hash + chb(0x5a) + b"\x00" * (7 - nb_extra_bytes)
# Hash
m_l, m_r = unpack('<II', key)
for i in range(nb_block + 2):
# Convert i-t... | [
"Defined",
"in",
"802",
".",
"11i",
"p",
".",
"48"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/modules/krack/crypto.py#L246-L261 | [
"def",
"michael",
"(",
"key",
",",
"to_hash",
")",
":",
"# Block size: 4",
"nb_block",
",",
"nb_extra_bytes",
"=",
"divmod",
"(",
"len",
"(",
"to_hash",
")",
",",
"4",
")",
"# Add padding",
"data",
"=",
"to_hash",
"+",
"chb",
"(",
"0x5a",
")",
"+",
"b\... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | parse_TKIP_hdr | Extract TSCs, TA and encoded-data from a packet @pkt | scapy/modules/krack/crypto.py | def parse_TKIP_hdr(pkt):
"""Extract TSCs, TA and encoded-data from a packet @pkt"""
# Note: FCS bit is not handled
assert pkt.FCfield.protected
# 802.11i - 8.3.2.2
tkip_layer = pkt[Dot11TKIP]
payload = tkip_layer.data
# IV
if not tkip_layer.ext_iv:
# 802.11i p. 46
raise... | def parse_TKIP_hdr(pkt):
"""Extract TSCs, TA and encoded-data from a packet @pkt"""
# Note: FCS bit is not handled
assert pkt.FCfield.protected
# 802.11i - 8.3.2.2
tkip_layer = pkt[Dot11TKIP]
payload = tkip_layer.data
# IV
if not tkip_layer.ext_iv:
# 802.11i p. 46
raise... | [
"Extract",
"TSCs",
"TA",
"and",
"encoded",
"-",
"data",
"from",
"a",
"packet"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/modules/krack/crypto.py#L266-L295 | [
"def",
"parse_TKIP_hdr",
"(",
"pkt",
")",
":",
"# Note: FCS bit is not handled",
"assert",
"pkt",
".",
"FCfield",
".",
"protected",
"# 802.11i - 8.3.2.2",
"tkip_layer",
"=",
"pkt",
"[",
"Dot11TKIP",
"]",
"payload",
"=",
"tkip_layer",
".",
"data",
"# IV",
"if",
"... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | build_TKIP_payload | Build a TKIP header for IV @iv and mac @mac, and encrypt @data
based on temporal key @tk | scapy/modules/krack/crypto.py | def build_TKIP_payload(data, iv, mac, tk):
"""Build a TKIP header for IV @iv and mac @mac, and encrypt @data
based on temporal key @tk
"""
TSC5, TSC4, TSC3, TSC2, TSC1, TSC0 = (
(iv >> 40) & 0xFF,
(iv >> 32) & 0xFF,
(iv >> 24) & 0xFF,
(iv >> 16) & 0xFF,
(iv >> 8) ... | def build_TKIP_payload(data, iv, mac, tk):
"""Build a TKIP header for IV @iv and mac @mac, and encrypt @data
based on temporal key @tk
"""
TSC5, TSC4, TSC3, TSC2, TSC1, TSC0 = (
(iv >> 40) & 0xFF,
(iv >> 32) & 0xFF,
(iv >> 24) & 0xFF,
(iv >> 16) & 0xFF,
(iv >> 8) ... | [
"Build",
"a",
"TKIP",
"header",
"for",
"IV"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/modules/krack/crypto.py#L298-L319 | [
"def",
"build_TKIP_payload",
"(",
"data",
",",
"iv",
",",
"mac",
",",
"tk",
")",
":",
"TSC5",
",",
"TSC4",
",",
"TSC3",
",",
"TSC2",
",",
"TSC1",
",",
"TSC0",
"=",
"(",
"(",
"iv",
">>",
"40",
")",
"&",
"0xFF",
",",
"(",
"iv",
">>",
"32",
")",... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | parse_data_pkt | Extract data from a WPA packet @pkt with temporal key @tk | scapy/modules/krack/crypto.py | def parse_data_pkt(pkt, tk):
"""Extract data from a WPA packet @pkt with temporal key @tk"""
TSC, TA, data = parse_TKIP_hdr(pkt)
TK = [orb(x) for x in tk]
rc4_key = gen_TKIP_RC4_key(TSC, TA, TK)
return ARC4_decrypt(rc4_key, data) | def parse_data_pkt(pkt, tk):
"""Extract data from a WPA packet @pkt with temporal key @tk"""
TSC, TA, data = parse_TKIP_hdr(pkt)
TK = [orb(x) for x in tk]
rc4_key = gen_TKIP_RC4_key(TSC, TA, TK)
return ARC4_decrypt(rc4_key, data) | [
"Extract",
"data",
"from",
"a",
"WPA",
"packet"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/modules/krack/crypto.py#L322-L328 | [
"def",
"parse_data_pkt",
"(",
"pkt",
",",
"tk",
")",
":",
"TSC",
",",
"TA",
",",
"data",
"=",
"parse_TKIP_hdr",
"(",
"pkt",
")",
"TK",
"=",
"[",
"orb",
"(",
"x",
")",
"for",
"x",
"in",
"tk",
"]",
"rc4_key",
"=",
"gen_TKIP_RC4_key",
"(",
"TSC",
",... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | check_MIC_ICV | Check MIC, ICV & return the data from a decrypted TKIP packet | scapy/modules/krack/crypto.py | def check_MIC_ICV(data, mic_key, source, dest):
"""Check MIC, ICV & return the data from a decrypted TKIP packet"""
assert len(data) > 12
# DATA - MIC(DA - SA - Priority=0 - 0 - 0 - 0 - DATA) - ICV
# 802.11i p.47
ICV = data[-4:]
MIC = data[-12:-4]
data_clear = data[:-12]
expected_ICV ... | def check_MIC_ICV(data, mic_key, source, dest):
"""Check MIC, ICV & return the data from a decrypted TKIP packet"""
assert len(data) > 12
# DATA - MIC(DA - SA - Priority=0 - 0 - 0 - 0 - DATA) - ICV
# 802.11i p.47
ICV = data[-4:]
MIC = data[-12:-4]
data_clear = data[:-12]
expected_ICV ... | [
"Check",
"MIC",
"ICV",
"&",
"return",
"the",
"data",
"from",
"a",
"decrypted",
"TKIP",
"packet"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/modules/krack/crypto.py#L341-L363 | [
"def",
"check_MIC_ICV",
"(",
"data",
",",
"mic_key",
",",
"source",
",",
"dest",
")",
":",
"assert",
"len",
"(",
"data",
")",
">",
"12",
"# DATA - MIC(DA - SA - Priority=0 - 0 - 0 - 0 - DATA) - ICV",
"# 802.11i p.47",
"ICV",
"=",
"data",
"[",
"-",
"4",
":",
"]... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | build_MIC_ICV | Compute and return the data with its MIC and ICV | scapy/modules/krack/crypto.py | def build_MIC_ICV(data, mic_key, source, dest):
"""Compute and return the data with its MIC and ICV"""
# DATA - MIC(DA - SA - Priority=0 - 0 - 0 - 0 - DATA) - ICV
# 802.11i p.47
sa = mac2str(source) # Source MAC
da = mac2str(dest) # Dest MAC
MIC = michael(mic_key, da + sa + b"\x00" + b"\x00" ... | def build_MIC_ICV(data, mic_key, source, dest):
"""Compute and return the data with its MIC and ICV"""
# DATA - MIC(DA - SA - Priority=0 - 0 - 0 - 0 - DATA) - ICV
# 802.11i p.47
sa = mac2str(source) # Source MAC
da = mac2str(dest) # Dest MAC
MIC = michael(mic_key, da + sa + b"\x00" + b"\x00" ... | [
"Compute",
"and",
"return",
"the",
"data",
"with",
"its",
"MIC",
"and",
"ICV"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/modules/krack/crypto.py#L366-L376 | [
"def",
"build_MIC_ICV",
"(",
"data",
",",
"mic_key",
",",
"source",
",",
"dest",
")",
":",
"# DATA - MIC(DA - SA - Priority=0 - 0 - 0 - 0 - DATA) - ICV",
"# 802.11i p.47",
"sa",
"=",
"mac2str",
"(",
"source",
")",
"# Source MAC",
"da",
"=",
"mac2str",
"(",
"dest",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | _lcm | Least Common Multiple between 2 integers. | scapy/layers/ipsec.py | def _lcm(a, b):
"""
Least Common Multiple between 2 integers.
"""
if a == 0 or b == 0:
return 0
else:
return abs(a * b) // gcd(a, b) | def _lcm(a, b):
"""
Least Common Multiple between 2 integers.
"""
if a == 0 or b == 0:
return 0
else:
return abs(a * b) // gcd(a, b) | [
"Least",
"Common",
"Multiple",
"between",
"2",
"integers",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/ipsec.py#L186-L193 | [
"def",
"_lcm",
"(",
"a",
",",
"b",
")",
":",
"if",
"a",
"==",
"0",
"or",
"b",
"==",
"0",
":",
"return",
"0",
"else",
":",
"return",
"abs",
"(",
"a",
"*",
"b",
")",
"//",
"gcd",
"(",
"a",
",",
"b",
")"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | split_for_transport | Split an IP(v6) packet in the correct location to insert an ESP or AH
header.
@param orig_pkt: the packet to split. Must be an IP or IPv6 packet
@param transport_proto: the IPsec protocol number that will be inserted
at the split position.
@return: a tuple (header, nh, paylo... | scapy/layers/ipsec.py | def split_for_transport(orig_pkt, transport_proto):
"""
Split an IP(v6) packet in the correct location to insert an ESP or AH
header.
@param orig_pkt: the packet to split. Must be an IP or IPv6 packet
@param transport_proto: the IPsec protocol number that will be inserted
... | def split_for_transport(orig_pkt, transport_proto):
"""
Split an IP(v6) packet in the correct location to insert an ESP or AH
header.
@param orig_pkt: the packet to split. Must be an IP or IPv6 packet
@param transport_proto: the IPsec protocol number that will be inserted
... | [
"Split",
"an",
"IP",
"(",
"v6",
")",
"packet",
"in",
"the",
"correct",
"location",
"to",
"insert",
"an",
"ESP",
"or",
"AH",
"header",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/ipsec.py#L642-L688 | [
"def",
"split_for_transport",
"(",
"orig_pkt",
",",
"transport_proto",
")",
":",
"# force resolution of default fields to avoid padding errors",
"header",
"=",
"orig_pkt",
".",
"__class__",
"(",
"raw",
"(",
"orig_pkt",
")",
")",
"next_hdr",
"=",
"header",
".",
"payloa... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | CryptAlgo.new_cipher | @param key: the secret key, a byte string
@param mode_iv: the initialization vector or nonce, a byte string.
Formatted by `format_mode_iv`.
@param digest: also known as tag or icv. A byte string containing the
digest of the encrypted data. Only use th... | scapy/layers/ipsec.py | def new_cipher(self, key, mode_iv, digest=None):
"""
@param key: the secret key, a byte string
@param mode_iv: the initialization vector or nonce, a byte string.
Formatted by `format_mode_iv`.
@param digest: also known as tag or icv. A byte string containing ... | def new_cipher(self, key, mode_iv, digest=None):
"""
@param key: the secret key, a byte string
@param mode_iv: the initialization vector or nonce, a byte string.
Formatted by `format_mode_iv`.
@param digest: also known as tag or icv. A byte string containing ... | [
"@param",
"key",
":",
"the",
"secret",
"key",
"a",
"byte",
"string",
"@param",
"mode_iv",
":",
"the",
"initialization",
"vector",
"or",
"nonce",
"a",
"byte",
"string",
".",
"Formatted",
"by",
"format_mode_iv",
".",
"@param",
"digest",
":",
"also",
"known",
... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/ipsec.py#L281-L304 | [
"def",
"new_cipher",
"(",
"self",
",",
"key",
",",
"mode_iv",
",",
"digest",
"=",
"None",
")",
":",
"if",
"self",
".",
"is_aead",
"and",
"digest",
"is",
"not",
"None",
":",
"# With AEAD, the mode needs the digest during decryption.",
"return",
"Cipher",
"(",
"... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | CryptAlgo.pad | Add the correct amount of padding so that the data to encrypt is
exactly a multiple of the algorithm's block size.
Also, make sure that the total ESP packet length is a multiple of 4
bytes.
@param esp: an unencrypted _ESPPlain packet
@return: an unencrypted _ESPPlain pac... | scapy/layers/ipsec.py | def pad(self, esp):
"""
Add the correct amount of padding so that the data to encrypt is
exactly a multiple of the algorithm's block size.
Also, make sure that the total ESP packet length is a multiple of 4
bytes.
@param esp: an unencrypted _ESPPlain packet
... | def pad(self, esp):
"""
Add the correct amount of padding so that the data to encrypt is
exactly a multiple of the algorithm's block size.
Also, make sure that the total ESP packet length is a multiple of 4
bytes.
@param esp: an unencrypted _ESPPlain packet
... | [
"Add",
"the",
"correct",
"amount",
"of",
"padding",
"so",
"that",
"the",
"data",
"to",
"encrypt",
"is",
"exactly",
"a",
"multiple",
"of",
"the",
"algorithm",
"s",
"block",
"size",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/ipsec.py#L306-L339 | [
"def",
"pad",
"(",
"self",
",",
"esp",
")",
":",
"# 2 extra bytes for padlen and nh",
"data_len",
"=",
"len",
"(",
"esp",
".",
"data",
")",
"+",
"2",
"# according to the RFC4303, section 2.4. Padding (for Encryption)",
"# the size of the ESP payload must be a multiple of 32 b... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | CryptAlgo.encrypt | Encrypt an ESP packet
@param sa: the SecurityAssociation associated with the ESP packet.
@param esp: an unencrypted _ESPPlain packet with valid padding
@param key: the secret key used for encryption
@return: a valid ESP packet encrypted with this algorithm | scapy/layers/ipsec.py | def encrypt(self, sa, esp, key):
"""
Encrypt an ESP packet
@param sa: the SecurityAssociation associated with the ESP packet.
@param esp: an unencrypted _ESPPlain packet with valid padding
@param key: the secret key used for encryption
@return: a valid ESP packet... | def encrypt(self, sa, esp, key):
"""
Encrypt an ESP packet
@param sa: the SecurityAssociation associated with the ESP packet.
@param esp: an unencrypted _ESPPlain packet with valid padding
@param key: the secret key used for encryption
@return: a valid ESP packet... | [
"Encrypt",
"an",
"ESP",
"packet"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/ipsec.py#L341-L366 | [
"def",
"encrypt",
"(",
"self",
",",
"sa",
",",
"esp",
",",
"key",
")",
":",
"data",
"=",
"esp",
".",
"data_for_encryption",
"(",
")",
"if",
"self",
".",
"cipher",
":",
"mode_iv",
"=",
"self",
".",
"_format_mode_iv",
"(",
"algo",
"=",
"self",
",",
"... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | AuthAlgo.check_key | Check that the key length is valid.
@param key: a byte string | scapy/layers/ipsec.py | def check_key(self, key):
"""
Check that the key length is valid.
@param key: a byte string
"""
if self.key_size and len(key) not in self.key_size:
raise TypeError('invalid key size %s, must be one of %s' %
(len(key), self.key_size)) | def check_key(self, key):
"""
Check that the key length is valid.
@param key: a byte string
"""
if self.key_size and len(key) not in self.key_size:
raise TypeError('invalid key size %s, must be one of %s' %
(len(key), self.key_size)) | [
"Check",
"that",
"the",
"key",
"length",
"is",
"valid",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/ipsec.py#L516-L524 | [
"def",
"check_key",
"(",
"self",
",",
"key",
")",
":",
"if",
"self",
".",
"key_size",
"and",
"len",
"(",
"key",
")",
"not",
"in",
"self",
".",
"key_size",
":",
"raise",
"TypeError",
"(",
"'invalid key size %s, must be one of %s'",
"%",
"(",
"len",
"(",
"... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | AuthAlgo.sign | Sign an IPsec (ESP or AH) packet with this algo.
@param pkt: a packet that contains a valid encrypted ESP or AH layer
@param key: the authentication key, a byte string
@return: the signed packet | scapy/layers/ipsec.py | def sign(self, pkt, key):
"""
Sign an IPsec (ESP or AH) packet with this algo.
@param pkt: a packet that contains a valid encrypted ESP or AH layer
@param key: the authentication key, a byte string
@return: the signed packet
"""
if not self.mac:
... | def sign(self, pkt, key):
"""
Sign an IPsec (ESP or AH) packet with this algo.
@param pkt: a packet that contains a valid encrypted ESP or AH layer
@param key: the authentication key, a byte string
@return: the signed packet
"""
if not self.mac:
... | [
"Sign",
"an",
"IPsec",
"(",
"ESP",
"or",
"AH",
")",
"packet",
"with",
"this",
"algo",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/ipsec.py#L537-L560 | [
"def",
"sign",
"(",
"self",
",",
"pkt",
",",
"key",
")",
":",
"if",
"not",
"self",
".",
"mac",
":",
"return",
"pkt",
"mac",
"=",
"self",
".",
"new_mac",
"(",
"key",
")",
"if",
"pkt",
".",
"haslayer",
"(",
"ESP",
")",
":",
"mac",
".",
"update",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | AuthAlgo.verify | Check that the integrity check value (icv) of a packet is valid.
@param pkt: a packet that contains a valid encrypted ESP or AH layer
@param key: the authentication key, a byte string
@raise IPSecIntegrityError: if the integrity check fails | scapy/layers/ipsec.py | def verify(self, pkt, key):
"""
Check that the integrity check value (icv) of a packet is valid.
@param pkt: a packet that contains a valid encrypted ESP or AH layer
@param key: the authentication key, a byte string
@raise IPSecIntegrityError: if the integrity check fails... | def verify(self, pkt, key):
"""
Check that the integrity check value (icv) of a packet is valid.
@param pkt: a packet that contains a valid encrypted ESP or AH layer
@param key: the authentication key, a byte string
@raise IPSecIntegrityError: if the integrity check fails... | [
"Check",
"that",
"the",
"integrity",
"check",
"value",
"(",
"icv",
")",
"of",
"a",
"packet",
"is",
"valid",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/ipsec.py#L562-L598 | [
"def",
"verify",
"(",
"self",
",",
"pkt",
",",
"key",
")",
":",
"if",
"not",
"self",
".",
"mac",
"or",
"self",
".",
"icv_size",
"==",
"0",
":",
"return",
"mac",
"=",
"self",
".",
"new_mac",
"(",
"key",
")",
"pkt_icv",
"=",
"'not found'",
"computed_... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | SecurityAssociation.encrypt | Encrypt (and encapsulate) an IP(v6) packet with ESP or AH according
to this SecurityAssociation.
@param pkt: the packet to encrypt
@param seq_num: if specified, use this sequence number instead of the
generated one
@param iv: if specified, use this initi... | scapy/layers/ipsec.py | def encrypt(self, pkt, seq_num=None, iv=None):
"""
Encrypt (and encapsulate) an IP(v6) packet with ESP or AH according
to this SecurityAssociation.
@param pkt: the packet to encrypt
@param seq_num: if specified, use this sequence number instead of the
... | def encrypt(self, pkt, seq_num=None, iv=None):
"""
Encrypt (and encapsulate) an IP(v6) packet with ESP or AH according
to this SecurityAssociation.
@param pkt: the packet to encrypt
@param seq_num: if specified, use this sequence number instead of the
... | [
"Encrypt",
"(",
"and",
"encapsulate",
")",
"an",
"IP",
"(",
"v6",
")",
"packet",
"with",
"ESP",
"or",
"AH",
"according",
"to",
"this",
"SecurityAssociation",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/ipsec.py#L959-L978 | [
"def",
"encrypt",
"(",
"self",
",",
"pkt",
",",
"seq_num",
"=",
"None",
",",
"iv",
"=",
"None",
")",
":",
"if",
"not",
"isinstance",
"(",
"pkt",
",",
"self",
".",
"SUPPORTED_PROTOS",
")",
":",
"raise",
"TypeError",
"(",
"'cannot encrypt %s, supported proto... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | SecurityAssociation.decrypt | Decrypt (and decapsulate) an IP(v6) packet containing ESP or AH.
@param pkt: the packet to decrypt
@param verify: if False, do not perform the integrity check
@return: the decrypted/decapsulated packet
@raise IPSecIntegrityError: if the integrity check fails | scapy/layers/ipsec.py | def decrypt(self, pkt, verify=True):
"""
Decrypt (and decapsulate) an IP(v6) packet containing ESP or AH.
@param pkt: the packet to decrypt
@param verify: if False, do not perform the integrity check
@return: the decrypted/decapsulated packet
@raise IPSecIntegrityE... | def decrypt(self, pkt, verify=True):
"""
Decrypt (and decapsulate) an IP(v6) packet containing ESP or AH.
@param pkt: the packet to decrypt
@param verify: if False, do not perform the integrity check
@return: the decrypted/decapsulated packet
@raise IPSecIntegrityE... | [
"Decrypt",
"(",
"and",
"decapsulate",
")",
"an",
"IP",
"(",
"v6",
")",
"packet",
"containing",
"ESP",
"or",
"AH",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/ipsec.py#L1053-L1072 | [
"def",
"decrypt",
"(",
"self",
",",
"pkt",
",",
"verify",
"=",
"True",
")",
":",
"if",
"not",
"isinstance",
"(",
"pkt",
",",
"self",
".",
"SUPPORTED_PROTOS",
")",
":",
"raise",
"TypeError",
"(",
"'cannot decrypt %s, supported protos are %s'",
"%",
"(",
"pkt"... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | _AEADCipher._update_nonce_explicit | Increment the explicit nonce while avoiding any overflow. | scapy/layers/tls/crypto/cipher_aead.py | def _update_nonce_explicit(self):
"""
Increment the explicit nonce while avoiding any overflow.
"""
ne = self.nonce_explicit + 1
self.nonce_explicit = ne % 2**(self.nonce_explicit_len * 8) | def _update_nonce_explicit(self):
"""
Increment the explicit nonce while avoiding any overflow.
"""
ne = self.nonce_explicit + 1
self.nonce_explicit = ne % 2**(self.nonce_explicit_len * 8) | [
"Increment",
"the",
"explicit",
"nonce",
"while",
"avoiding",
"any",
"overflow",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/crypto/cipher_aead.py#L130-L135 | [
"def",
"_update_nonce_explicit",
"(",
"self",
")",
":",
"ne",
"=",
"self",
".",
"nonce_explicit",
"+",
"1",
"self",
".",
"nonce_explicit",
"=",
"ne",
"%",
"2",
"**",
"(",
"self",
".",
"nonce_explicit_len",
"*",
"8",
")"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | _AEADCipher.auth_encrypt | Encrypt the data then prepend the explicit part of the nonce. The
authentication tag is directly appended with the most recent crypto
API. Additional data may be authenticated without encryption (as A).
The 'seq_num' should never be used here, it is only a safeguard needed
because one c... | scapy/layers/tls/crypto/cipher_aead.py | def auth_encrypt(self, P, A, seq_num=None):
"""
Encrypt the data then prepend the explicit part of the nonce. The
authentication tag is directly appended with the most recent crypto
API. Additional data may be authenticated without encryption (as A).
The 'seq_num' should never b... | def auth_encrypt(self, P, A, seq_num=None):
"""
Encrypt the data then prepend the explicit part of the nonce. The
authentication tag is directly appended with the most recent crypto
API. Additional data may be authenticated without encryption (as A).
The 'seq_num' should never b... | [
"Encrypt",
"the",
"data",
"then",
"prepend",
"the",
"explicit",
"part",
"of",
"the",
"nonce",
".",
"The",
"authentication",
"tag",
"is",
"directly",
"appended",
"with",
"the",
"most",
"recent",
"crypto",
"API",
".",
"Additional",
"data",
"may",
"be",
"authen... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/crypto/cipher_aead.py#L137-L163 | [
"def",
"auth_encrypt",
"(",
"self",
",",
"P",
",",
"A",
",",
"seq_num",
"=",
"None",
")",
":",
"if",
"False",
"in",
"six",
".",
"itervalues",
"(",
"self",
".",
"ready",
")",
":",
"raise",
"CipherError",
"(",
"P",
",",
"A",
")",
"if",
"hasattr",
"... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | _AEADCipher.auth_decrypt | Decrypt the data and authenticate the associated data (i.e. A).
If the verification fails, an AEADTagError is raised. It is the user's
responsibility to catch it if deemed useful. If we lack the key, we
raise a CipherError which contains the encrypted input.
Note that we add the TLSCiph... | scapy/layers/tls/crypto/cipher_aead.py | def auth_decrypt(self, A, C, seq_num=None, add_length=True):
"""
Decrypt the data and authenticate the associated data (i.e. A).
If the verification fails, an AEADTagError is raised. It is the user's
responsibility to catch it if deemed useful. If we lack the key, we
raise a Ciph... | def auth_decrypt(self, A, C, seq_num=None, add_length=True):
"""
Decrypt the data and authenticate the associated data (i.e. A).
If the verification fails, an AEADTagError is raised. It is the user's
responsibility to catch it if deemed useful. If we lack the key, we
raise a Ciph... | [
"Decrypt",
"the",
"data",
"and",
"authenticate",
"the",
"associated",
"data",
"(",
"i",
".",
"e",
".",
"A",
")",
".",
"If",
"the",
"verification",
"fails",
"an",
"AEADTagError",
"is",
"raised",
".",
"It",
"is",
"the",
"user",
"s",
"responsibility",
"to",... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/crypto/cipher_aead.py#L165-L211 | [
"def",
"auth_decrypt",
"(",
"self",
",",
"A",
",",
"C",
",",
"seq_num",
"=",
"None",
",",
"add_length",
"=",
"True",
")",
":",
"nonce_explicit_str",
",",
"C",
",",
"mac",
"=",
"(",
"C",
"[",
":",
"self",
".",
"nonce_explicit_len",
"]",
",",
"C",
"[... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | _AEADCipher_TLS13.auth_encrypt | Encrypt the data, and append the computed authentication code.
TLS 1.3 does not use additional data, but we leave this option to the
user nonetheless.
Note that the cipher's authentication tag must be None when encrypting. | scapy/layers/tls/crypto/cipher_aead.py | def auth_encrypt(self, P, A, seq_num):
"""
Encrypt the data, and append the computed authentication code.
TLS 1.3 does not use additional data, but we leave this option to the
user nonetheless.
Note that the cipher's authentication tag must be None when encrypting.
"""
... | def auth_encrypt(self, P, A, seq_num):
"""
Encrypt the data, and append the computed authentication code.
TLS 1.3 does not use additional data, but we leave this option to the
user nonetheless.
Note that the cipher's authentication tag must be None when encrypting.
"""
... | [
"Encrypt",
"the",
"data",
"and",
"append",
"the",
"computed",
"authentication",
"code",
".",
"TLS",
"1",
".",
"3",
"does",
"not",
"use",
"additional",
"data",
"but",
"we",
"leave",
"this",
"option",
"to",
"the",
"user",
"nonetheless",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/crypto/cipher_aead.py#L308-L333 | [
"def",
"auth_encrypt",
"(",
"self",
",",
"P",
",",
"A",
",",
"seq_num",
")",
":",
"if",
"False",
"in",
"six",
".",
"itervalues",
"(",
"self",
".",
"ready",
")",
":",
"raise",
"CipherError",
"(",
"P",
",",
"A",
")",
"if",
"hasattr",
"(",
"self",
"... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | _AEADCipher_TLS13.auth_decrypt | Decrypt the data and verify the authentication code (in this order).
Note that TLS 1.3 is not supposed to use any additional data A.
If the verification fails, an AEADTagError is raised. It is the user's
responsibility to catch it if deemed useful. If we lack the key, we
raise a CipherEr... | scapy/layers/tls/crypto/cipher_aead.py | def auth_decrypt(self, A, C, seq_num):
"""
Decrypt the data and verify the authentication code (in this order).
Note that TLS 1.3 is not supposed to use any additional data A.
If the verification fails, an AEADTagError is raised. It is the user's
responsibility to catch it if dee... | def auth_decrypt(self, A, C, seq_num):
"""
Decrypt the data and verify the authentication code (in this order).
Note that TLS 1.3 is not supposed to use any additional data A.
If the verification fails, an AEADTagError is raised. It is the user's
responsibility to catch it if dee... | [
"Decrypt",
"the",
"data",
"and",
"verify",
"the",
"authentication",
"code",
"(",
"in",
"this",
"order",
")",
".",
"Note",
"that",
"TLS",
"1",
".",
"3",
"is",
"not",
"supposed",
"to",
"use",
"any",
"additional",
"data",
"A",
".",
"If",
"the",
"verificat... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/crypto/cipher_aead.py#L335-L370 | [
"def",
"auth_decrypt",
"(",
"self",
",",
"A",
",",
"C",
",",
"seq_num",
")",
":",
"C",
",",
"mac",
"=",
"C",
"[",
":",
"-",
"self",
".",
"tag_len",
"]",
",",
"C",
"[",
"-",
"self",
".",
"tag_len",
":",
"]",
"if",
"False",
"in",
"six",
".",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | _tzsp_guess_next_tag | :return: class representing the next tag, Raw on error, None on missing payload # noqa: E501 | scapy/contrib/tzsp.py | def _tzsp_guess_next_tag(payload):
"""
:return: class representing the next tag, Raw on error, None on missing payload # noqa: E501
"""
if not payload:
warning('missing payload')
return None
tag_type = orb(payload[0])
try:
tag_class_definition = _TZSP_TAG_CLASSES[tag_... | def _tzsp_guess_next_tag(payload):
"""
:return: class representing the next tag, Raw on error, None on missing payload # noqa: E501
"""
if not payload:
warning('missing payload')
return None
tag_type = orb(payload[0])
try:
tag_class_definition = _TZSP_TAG_CLASSES[tag_... | [
":",
"return",
":",
"class",
"representing",
"the",
"next",
"tag",
"Raw",
"on",
"error",
"None",
"on",
"missing",
"payload",
"#",
"noqa",
":",
"E501"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/tzsp.py#L153-L187 | [
"def",
"_tzsp_guess_next_tag",
"(",
"payload",
")",
":",
"if",
"not",
"payload",
":",
"warning",
"(",
"'missing payload'",
")",
"return",
"None",
"tag_type",
"=",
"orb",
"(",
"payload",
"[",
"0",
"]",
")",
"try",
":",
"tag_class_definition",
"=",
"_TZSP_TAG_... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | TZSP.get_encapsulated_payload_class | get the class that holds the encapsulated payload of the TZSP packet
:return: class representing the payload, Raw() on error | scapy/contrib/tzsp.py | def get_encapsulated_payload_class(self):
"""
get the class that holds the encapsulated payload of the TZSP packet
:return: class representing the payload, Raw() on error
"""
try:
return TZSP.ENCAPSULATED_PROTOCOL_CLASSES[self.encapsulated_protocol] # noqa: E501
... | def get_encapsulated_payload_class(self):
"""
get the class that holds the encapsulated payload of the TZSP packet
:return: class representing the payload, Raw() on error
"""
try:
return TZSP.ENCAPSULATED_PROTOCOL_CLASSES[self.encapsulated_protocol] # noqa: E501
... | [
"get",
"the",
"class",
"that",
"holds",
"the",
"encapsulated",
"payload",
"of",
"the",
"TZSP",
"packet",
":",
"return",
":",
"class",
"representing",
"the",
"payload",
"Raw",
"()",
"on",
"error"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/tzsp.py#L100-L111 | [
"def",
"get_encapsulated_payload_class",
"(",
"self",
")",
":",
"try",
":",
"return",
"TZSP",
".",
"ENCAPSULATED_PROTOCOL_CLASSES",
"[",
"self",
".",
"encapsulated_protocol",
"]",
"# noqa: E501",
"except",
"KeyError",
":",
"warning",
"(",
"'unknown or invalid encapsulat... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | TZSPTagEnd.guess_payload_class | the type of the payload encapsulation is given be the outer TZSP layers attribute encapsulation_protocol # noqa: E501 | scapy/contrib/tzsp.py | def guess_payload_class(self, payload):
"""
the type of the payload encapsulation is given be the outer TZSP layers attribute encapsulation_protocol # noqa: E501
"""
under_layer = self.underlayer
tzsp_header = None
while under_layer:
if isinstance(under_lay... | def guess_payload_class(self, payload):
"""
the type of the payload encapsulation is given be the outer TZSP layers attribute encapsulation_protocol # noqa: E501
"""
under_layer = self.underlayer
tzsp_header = None
while under_layer:
if isinstance(under_lay... | [
"the",
"type",
"of",
"the",
"payload",
"encapsulation",
"is",
"given",
"be",
"the",
"outer",
"TZSP",
"layers",
"attribute",
"encapsulation_protocol",
"#",
"noqa",
":",
"E501"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/tzsp.py#L246-L264 | [
"def",
"guess_payload_class",
"(",
"self",
",",
"payload",
")",
":",
"under_layer",
"=",
"self",
".",
"underlayer",
"tzsp_header",
"=",
"None",
"while",
"under_layer",
":",
"if",
"isinstance",
"(",
"under_layer",
",",
"TZSP",
")",
":",
"tzsp_header",
"=",
"u... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | ShortVersionField.h2i | The field accepts string values like v12.1, v1.1 or integer values.
String values have to start with a "v" folled by a floating point number.
Valid numbers are between 0 and 255. | scapy/contrib/eigrp.py | def h2i(self, pkt, x):
"""The field accepts string values like v12.1, v1.1 or integer values.
String values have to start with a "v" folled by a floating point number.
Valid numbers are between 0 and 255.
"""
if isinstance(x, str) and x.startswith("v") and len(x) <= 8:
... | def h2i(self, pkt, x):
"""The field accepts string values like v12.1, v1.1 or integer values.
String values have to start with a "v" folled by a floating point number.
Valid numbers are between 0 and 255.
"""
if isinstance(x, str) and x.startswith("v") and len(x) <= 8:
... | [
"The",
"field",
"accepts",
"string",
"values",
"like",
"v12",
".",
"1",
"v1",
".",
"1",
"or",
"integer",
"values",
".",
"String",
"values",
"have",
"to",
"start",
"with",
"a",
"v",
"folled",
"by",
"a",
"floating",
"point",
"number",
".",
"Valid",
"numb... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/eigrp.py#L284-L305 | [
"def",
"h2i",
"(",
"self",
",",
"pkt",
",",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"str",
")",
"and",
"x",
".",
"startswith",
"(",
"\"v\"",
")",
"and",
"len",
"(",
"x",
")",
"<=",
"8",
":",
"major",
"=",
"int",
"(",
"x",
".",
"sp... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | get_algs_from_ciphersuite_name | Return the 3-tuple made of the Key Exchange Algorithm class, the Cipher
class and the HMAC class, through the parsing of the ciphersuite name. | scapy/layers/tls/crypto/suites.py | def get_algs_from_ciphersuite_name(ciphersuite_name):
"""
Return the 3-tuple made of the Key Exchange Algorithm class, the Cipher
class and the HMAC class, through the parsing of the ciphersuite name.
"""
tls1_3 = False
if ciphersuite_name.startswith("TLS"):
s = ciphersuite_name[4:]
... | def get_algs_from_ciphersuite_name(ciphersuite_name):
"""
Return the 3-tuple made of the Key Exchange Algorithm class, the Cipher
class and the HMAC class, through the parsing of the ciphersuite name.
"""
tls1_3 = False
if ciphersuite_name.startswith("TLS"):
s = ciphersuite_name[4:]
... | [
"Return",
"the",
"3",
"-",
"tuple",
"made",
"of",
"the",
"Key",
"Exchange",
"Algorithm",
"class",
"the",
"Cipher",
"class",
"and",
"the",
"HMAC",
"class",
"through",
"the",
"parsing",
"of",
"the",
"ciphersuite",
"name",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/crypto/suites.py#L21-L67 | [
"def",
"get_algs_from_ciphersuite_name",
"(",
"ciphersuite_name",
")",
":",
"tls1_3",
"=",
"False",
"if",
"ciphersuite_name",
".",
"startswith",
"(",
"\"TLS\"",
")",
":",
"s",
"=",
"ciphersuite_name",
"[",
"4",
":",
"]",
"if",
"s",
".",
"endswith",
"(",
"\"C... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | get_usable_ciphersuites | From a list of proposed ciphersuites, this function returns a list of
usable cipher suites, i.e. for which key exchange, cipher and hash
algorithms are known to be implemented and usable in current version of the
TLS extension. The order of the cipher suites in the list returned by the
function matches ... | scapy/layers/tls/crypto/suites.py | def get_usable_ciphersuites(l, kx):
"""
From a list of proposed ciphersuites, this function returns a list of
usable cipher suites, i.e. for which key exchange, cipher and hash
algorithms are known to be implemented and usable in current version of the
TLS extension. The order of the cipher suites i... | def get_usable_ciphersuites(l, kx):
"""
From a list of proposed ciphersuites, this function returns a list of
usable cipher suites, i.e. for which key exchange, cipher and hash
algorithms are known to be implemented and usable in current version of the
TLS extension. The order of the cipher suites i... | [
"From",
"a",
"list",
"of",
"proposed",
"ciphersuites",
"this",
"function",
"returns",
"a",
"list",
"of",
"usable",
"cipher",
"suites",
"i",
".",
"e",
".",
"for",
"which",
"key",
"exchange",
"cipher",
"and",
"hash",
"algorithms",
"are",
"known",
"to",
"be",... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/tls/crypto/suites.py#L1300-L1317 | [
"def",
"get_usable_ciphersuites",
"(",
"l",
",",
"kx",
")",
":",
"res",
"=",
"[",
"]",
"for",
"c",
"in",
"l",
":",
"if",
"c",
"in",
"_tls_cipher_suites_cls",
":",
"ciph",
"=",
"_tls_cipher_suites_cls",
"[",
"c",
"]",
"if",
"ciph",
".",
"usable",
":",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | in4_chksum | As Specified in RFC 2460 - 8.1 Upper-Layer Checksums
Performs IPv4 Upper Layer checksum computation. Provided parameters are:
- 'proto' : value of upper layer protocol
- 'u' : IP upper layer instance
- 'p' : the payload of the upper layer provided as a string | scapy/layers/inet.py | def in4_chksum(proto, u, p):
"""
As Specified in RFC 2460 - 8.1 Upper-Layer Checksums
Performs IPv4 Upper Layer checksum computation. Provided parameters are:
- 'proto' : value of upper layer protocol
- 'u' : IP upper layer instance
- 'p' : the payload of the upper layer provided as a string
... | def in4_chksum(proto, u, p):
"""
As Specified in RFC 2460 - 8.1 Upper-Layer Checksums
Performs IPv4 Upper Layer checksum computation. Provided parameters are:
- 'proto' : value of upper layer protocol
- 'u' : IP upper layer instance
- 'p' : the payload of the upper layer provided as a string
... | [
"As",
"Specified",
"in",
"RFC",
"2460",
"-",
"8",
".",
"1",
"Upper",
"-",
"Layer",
"Checksums"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet.py#L578-L604 | [
"def",
"in4_chksum",
"(",
"proto",
",",
"u",
",",
"p",
")",
":",
"if",
"not",
"isinstance",
"(",
"u",
",",
"IP",
")",
":",
"warning",
"(",
"\"No IP underlayer to compute checksum. Leaving null.\"",
")",
"return",
"0",
"if",
"u",
".",
"len",
"is",
"not",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | _defrag_list | Internal usage only. Part of the _defrag_logic | scapy/layers/inet.py | def _defrag_list(lst, defrag, missfrag):
"""Internal usage only. Part of the _defrag_logic"""
p = lst[0]
lastp = lst[-1]
if p.frag > 0 or lastp.flags.MF: # first or last fragment missing
missfrag.append(lst)
return
p = p.copy()
if conf.padding_layer in p:
del(p[conf.padd... | def _defrag_list(lst, defrag, missfrag):
"""Internal usage only. Part of the _defrag_logic"""
p = lst[0]
lastp = lst[-1]
if p.frag > 0 or lastp.flags.MF: # first or last fragment missing
missfrag.append(lst)
return
p = p.copy()
if conf.padding_layer in p:
del(p[conf.padd... | [
"Internal",
"usage",
"only",
".",
"Part",
"of",
"the",
"_defrag_logic"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet.py#L1018-L1055 | [
"def",
"_defrag_list",
"(",
"lst",
",",
"defrag",
",",
"missfrag",
")",
":",
"p",
"=",
"lst",
"[",
"0",
"]",
"lastp",
"=",
"lst",
"[",
"-",
"1",
"]",
"if",
"p",
".",
"frag",
">",
"0",
"or",
"lastp",
".",
"flags",
".",
"MF",
":",
"# first or las... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | _defrag_logic | Internal function used to defragment a list of packets.
It contains the logic behind the defrag() and defragment() functions | scapy/layers/inet.py | def _defrag_logic(plist, complete=False):
"""Internal function used to defragment a list of packets.
It contains the logic behind the defrag() and defragment() functions
"""
frags = defaultdict(lambda: [])
final = []
pos = 0
for p in plist:
p._defrag_pos = pos
pos += 1
... | def _defrag_logic(plist, complete=False):
"""Internal function used to defragment a list of packets.
It contains the logic behind the defrag() and defragment() functions
"""
frags = defaultdict(lambda: [])
final = []
pos = 0
for p in plist:
p._defrag_pos = pos
pos += 1
... | [
"Internal",
"function",
"used",
"to",
"defragment",
"a",
"list",
"of",
"packets",
".",
"It",
"contains",
"the",
"logic",
"behind",
"the",
"defrag",
"()",
"and",
"defragment",
"()",
"functions"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet.py#L1058-L1097 | [
"def",
"_defrag_logic",
"(",
"plist",
",",
"complete",
"=",
"False",
")",
":",
"frags",
"=",
"defaultdict",
"(",
"lambda",
":",
"[",
"]",
")",
"final",
"=",
"[",
"]",
"pos",
"=",
"0",
"for",
"p",
"in",
"plist",
":",
"p",
".",
"_defrag_pos",
"=",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | _packetlist_timeskew_graph | Tries to graph the timeskew between the timestamps and real time for a given ip | scapy/layers/inet.py | def _packetlist_timeskew_graph(self, ip, **kargs):
"""Tries to graph the timeskew between the timestamps and real time for a given ip""" # noqa: E501
# Filter TCP segments which source address is 'ip'
tmp = (self._elt2pkt(x) for x in self.res)
b = (x for x in tmp if IP in x and x[IP].src == ip and TCP... | def _packetlist_timeskew_graph(self, ip, **kargs):
"""Tries to graph the timeskew between the timestamps and real time for a given ip""" # noqa: E501
# Filter TCP segments which source address is 'ip'
tmp = (self._elt2pkt(x) for x in self.res)
b = (x for x in tmp if IP in x and x[IP].src == ip and TCP... | [
"Tries",
"to",
"graph",
"the",
"timeskew",
"between",
"the",
"timestamps",
"and",
"real",
"time",
"for",
"a",
"given",
"ip"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet.py#L1114-L1159 | [
"def",
"_packetlist_timeskew_graph",
"(",
"self",
",",
"ip",
",",
"*",
"*",
"kargs",
")",
":",
"# noqa: E501",
"# Filter TCP segments which source address is 'ip'",
"tmp",
"=",
"(",
"self",
".",
"_elt2pkt",
"(",
"x",
")",
"for",
"x",
"in",
"self",
".",
"res",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | traceroute | Instant TCP traceroute
traceroute(target, [maxttl=30,] [dport=80,] [sport=80,] [verbose=conf.verb]) -> None # noqa: E501 | scapy/layers/inet.py | def traceroute(target, dport=80, minttl=1, maxttl=30, sport=RandShort(), l4=None, filter=None, timeout=2, verbose=None, **kargs): # noqa: E501
"""Instant TCP traceroute
traceroute(target, [maxttl=30,] [dport=80,] [sport=80,] [verbose=conf.verb]) -> None # noqa: E501
"""
if verbose is None:
verbose = c... | def traceroute(target, dport=80, minttl=1, maxttl=30, sport=RandShort(), l4=None, filter=None, timeout=2, verbose=None, **kargs): # noqa: E501
"""Instant TCP traceroute
traceroute(target, [maxttl=30,] [dport=80,] [sport=80,] [verbose=conf.verb]) -> None # noqa: E501
"""
if verbose is None:
verbose = c... | [
"Instant",
"TCP",
"traceroute",
"traceroute",
"(",
"target",
"[",
"maxttl",
"=",
"30",
"]",
"[",
"dport",
"=",
"80",
"]",
"[",
"sport",
"=",
"80",
"]",
"[",
"verbose",
"=",
"conf",
".",
"verb",
"]",
")",
"-",
">",
"None",
"#",
"noqa",
":",
"E501"... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet.py#L1643-L1666 | [
"def",
"traceroute",
"(",
"target",
",",
"dport",
"=",
"80",
",",
"minttl",
"=",
"1",
",",
"maxttl",
"=",
"30",
",",
"sport",
"=",
"RandShort",
"(",
")",
",",
"l4",
"=",
"None",
",",
"filter",
"=",
"None",
",",
"timeout",
"=",
"2",
",",
"verbose"... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | report_ports | portscan a target and output a LaTeX table
report_ports(target, ports) -> string | scapy/layers/inet.py | def report_ports(target, ports):
"""portscan a target and output a LaTeX table
report_ports(target, ports) -> string"""
ans, unans = sr(IP(dst=target) / TCP(dport=ports), timeout=5)
rep = "\\begin{tabular}{|r|l|l|}\n\\hline\n"
for s, r in ans:
if not r.haslayer(ICMP):
if r.payload.fl... | def report_ports(target, ports):
"""portscan a target and output a LaTeX table
report_ports(target, ports) -> string"""
ans, unans = sr(IP(dst=target) / TCP(dport=ports), timeout=5)
rep = "\\begin{tabular}{|r|l|l|}\n\\hline\n"
for s, r in ans:
if not r.haslayer(ICMP):
if r.payload.fl... | [
"portscan",
"a",
"target",
"and",
"output",
"a",
"LaTeX",
"table",
"report_ports",
"(",
"target",
"ports",
")",
"-",
">",
"string"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet.py#L1811-L1830 | [
"def",
"report_ports",
"(",
"target",
",",
"ports",
")",
":",
"ans",
",",
"unans",
"=",
"sr",
"(",
"IP",
"(",
"dst",
"=",
"target",
")",
"/",
"TCP",
"(",
"dport",
"=",
"ports",
")",
",",
"timeout",
"=",
"5",
")",
"rep",
"=",
"\"\\\\begin{tabular}{|... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | IPID_count | Identify IP id values classes in a list of packets
lst: a list of packets
funcID: a function that returns IP id values
funcpres: a function used to summarize packets | scapy/layers/inet.py | def IPID_count(lst, funcID=lambda x: x[1].id, funcpres=lambda x: x[1].summary()): # noqa: E501
"""Identify IP id values classes in a list of packets
lst: a list of packets
funcID: a function that returns IP id values
funcpres: a function used to summarize packets"""
idlst = [funcID(e) for e in lst]
... | def IPID_count(lst, funcID=lambda x: x[1].id, funcpres=lambda x: x[1].summary()): # noqa: E501
"""Identify IP id values classes in a list of packets
lst: a list of packets
funcID: a function that returns IP id values
funcpres: a function used to summarize packets"""
idlst = [funcID(e) for e in lst]
... | [
"Identify",
"IP",
"id",
"values",
"classes",
"in",
"a",
"list",
"of",
"packets"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet.py#L1834-L1848 | [
"def",
"IPID_count",
"(",
"lst",
",",
"funcID",
"=",
"lambda",
"x",
":",
"x",
"[",
"1",
"]",
".",
"id",
",",
"funcpres",
"=",
"lambda",
"x",
":",
"x",
"[",
"1",
"]",
".",
"summary",
"(",
")",
")",
":",
"# noqa: E501",
"idlst",
"=",
"[",
"funcID... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | IPTools._ttl | Returns ttl or hlim, depending on the IP version | scapy/layers/inet.py | def _ttl(self):
"""Returns ttl or hlim, depending on the IP version"""
return self.hlim if isinstance(self, scapy.layers.inet6.IPv6) else self.ttl | def _ttl(self):
"""Returns ttl or hlim, depending on the IP version"""
return self.hlim if isinstance(self, scapy.layers.inet6.IPv6) else self.ttl | [
"Returns",
"ttl",
"or",
"hlim",
"depending",
"on",
"the",
"IP",
"version"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet.py#L62-L64 | [
"def",
"_ttl",
"(",
"self",
")",
":",
"return",
"self",
".",
"hlim",
"if",
"isinstance",
"(",
"self",
",",
"scapy",
".",
"layers",
".",
"inet6",
".",
"IPv6",
")",
"else",
"self",
".",
"ttl"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | TracerouteResult.trace3D | Give a 3D representation of the traceroute.
right button: rotate the scene
middle button: zoom
shift-left button: move the scene
left button on a ball: toggle IP displaying
double-click button on a ball: scan ports 21,22,23,25,80 and 443 and display the result | scapy/layers/inet.py | def trace3D(self, join=True):
"""Give a 3D representation of the traceroute.
right button: rotate the scene
middle button: zoom
shift-left button: move the scene
left button on a ball: toggle IP displaying
double-click button on a ball: scan ports 21,22,23,25,80 and 443 a... | def trace3D(self, join=True):
"""Give a 3D representation of the traceroute.
right button: rotate the scene
middle button: zoom
shift-left button: move the scene
left button on a ball: toggle IP displaying
double-click button on a ball: scan ports 21,22,23,25,80 and 443 a... | [
"Give",
"a",
"3D",
"representation",
"of",
"the",
"traceroute",
".",
"right",
"button",
":",
"rotate",
"the",
"scene",
"middle",
"button",
":",
"zoom",
"shift",
"-",
"left",
"button",
":",
"move",
"the",
"scene",
"left",
"button",
"on",
"a",
"ball",
":",... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet.py#L1202-L1215 | [
"def",
"trace3D",
"(",
"self",
",",
"join",
"=",
"True",
")",
":",
"# noqa: E501",
"# When not ran from a notebook, vpython pooly closes itself",
"# using os._exit once finished. We pack it into a Process",
"import",
"multiprocessing",
"p",
"=",
"multiprocessing",
".",
"Process... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | TracerouteResult.trace3D_notebook | Same than trace3D, used when ran from Jupyther notebooks | scapy/layers/inet.py | def trace3D_notebook(self):
"""Same than trace3D, used when ran from Jupyther notebooks"""
trace = self.get_trace()
import vpython
class IPsphere(vpython.sphere):
def __init__(self, ip, **kargs):
vpython.sphere.__init__(self, **kargs)
self.ip ... | def trace3D_notebook(self):
"""Same than trace3D, used when ran from Jupyther notebooks"""
trace = self.get_trace()
import vpython
class IPsphere(vpython.sphere):
def __init__(self, ip, **kargs):
vpython.sphere.__init__(self, **kargs)
self.ip ... | [
"Same",
"than",
"trace3D",
"used",
"when",
"ran",
"from",
"Jupyther",
"notebooks"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet.py#L1217-L1362 | [
"def",
"trace3D_notebook",
"(",
"self",
")",
":",
"trace",
"=",
"self",
".",
"get_trace",
"(",
")",
"import",
"vpython",
"class",
"IPsphere",
"(",
"vpython",
".",
"sphere",
")",
":",
"def",
"__init__",
"(",
"self",
",",
"ip",
",",
"*",
"*",
"kargs",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | TracerouteResult.world_trace | Display traceroute results on a world map. | scapy/layers/inet.py | def world_trace(self):
"""Display traceroute results on a world map."""
# Check that the geoip2 module can be imported
# Doc: http://geoip2.readthedocs.io/en/latest/
try:
# GeoIP2 modules need to be imported as below
import geoip2.database
import geoi... | def world_trace(self):
"""Display traceroute results on a world map."""
# Check that the geoip2 module can be imported
# Doc: http://geoip2.readthedocs.io/en/latest/
try:
# GeoIP2 modules need to be imported as below
import geoip2.database
import geoi... | [
"Display",
"traceroute",
"results",
"on",
"a",
"world",
"map",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet.py#L1364-L1480 | [
"def",
"world_trace",
"(",
"self",
")",
":",
"# Check that the geoip2 module can be imported",
"# Doc: http://geoip2.readthedocs.io/en/latest/",
"try",
":",
"# GeoIP2 modules need to be imported as below",
"import",
"geoip2",
".",
"database",
"import",
"geoip2",
".",
"errors",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | TracerouteResult.graph | x.graph(ASres=conf.AS_resolver, other args):
ASres=None : no AS resolver => no clustering
ASres=AS_resolver() : default whois AS resolver (riswhois.ripe.net)
ASres=AS_resolver_cymru(): use whois.cymru.com whois database
ASres=AS_resolver(server="whois.ra.net")
type: outp... | scapy/layers/inet.py | def graph(self, ASres=conf.AS_resolver, padding=0, **kargs):
"""x.graph(ASres=conf.AS_resolver, other args):
ASres=None : no AS resolver => no clustering
ASres=AS_resolver() : default whois AS resolver (riswhois.ripe.net)
ASres=AS_resolver_cymru(): use whois.cymru.com whois data... | def graph(self, ASres=conf.AS_resolver, padding=0, **kargs):
"""x.graph(ASres=conf.AS_resolver, other args):
ASres=None : no AS resolver => no clustering
ASres=AS_resolver() : default whois AS resolver (riswhois.ripe.net)
ASres=AS_resolver_cymru(): use whois.cymru.com whois data... | [
"x",
".",
"graph",
"(",
"ASres",
"=",
"conf",
".",
"AS_resolver",
"other",
"args",
")",
":",
"ASres",
"=",
"None",
":",
"no",
"AS",
"resolver",
"=",
">",
"no",
"clustering",
"ASres",
"=",
"AS_resolver",
"()",
":",
"default",
"whois",
"AS",
"resolver",
... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/layers/inet.py#L1625-L1639 | [
"def",
"graph",
"(",
"self",
",",
"ASres",
"=",
"conf",
".",
"AS_resolver",
",",
"padding",
"=",
"0",
",",
"*",
"*",
"kargs",
")",
":",
"if",
"(",
"self",
".",
"graphdef",
"is",
"None",
"or",
"self",
".",
"graphASres",
"!=",
"ASres",
"or",
"self",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | ASN1F_field.m2i | The good thing about safedec is that it may still decode ASN1
even if there is a mismatch between the expected tag (self.ASN1_tag)
and the actual tag; the decoded ASN1 object will simply be put
into an ASN1_BADTAG object. However, safedec prevents the raising of
exceptions needed for ASN... | scapy/asn1fields.py | def m2i(self, pkt, s):
"""
The good thing about safedec is that it may still decode ASN1
even if there is a mismatch between the expected tag (self.ASN1_tag)
and the actual tag; the decoded ASN1 object will simply be put
into an ASN1_BADTAG object. However, safedec prevents the r... | def m2i(self, pkt, s):
"""
The good thing about safedec is that it may still decode ASN1
even if there is a mismatch between the expected tag (self.ASN1_tag)
and the actual tag; the decoded ASN1 object will simply be put
into an ASN1_BADTAG object. However, safedec prevents the r... | [
"The",
"good",
"thing",
"about",
"safedec",
"is",
"that",
"it",
"may",
"still",
"decode",
"ASN1",
"even",
"if",
"there",
"is",
"a",
"mismatch",
"between",
"the",
"expected",
"tag",
"(",
"self",
".",
"ASN1_tag",
")",
"and",
"the",
"actual",
"tag",
";",
... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/asn1fields.py#L74-L101 | [
"def",
"m2i",
"(",
"self",
",",
"pkt",
",",
"s",
")",
":",
"diff_tag",
",",
"s",
"=",
"BER_tagging_dec",
"(",
"s",
",",
"hidden_tag",
"=",
"self",
".",
"ASN1_tag",
",",
"implicit_tag",
"=",
"self",
".",
"implicit_tag",
",",
"explicit_tag",
"=",
"self",... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | ASN1F_SEQUENCE.m2i | ASN1F_SEQUENCE behaves transparently, with nested ASN1_objects being
dissected one by one. Because we use obj.dissect (see loop below)
instead of obj.m2i (as we trust dissect to do the appropriate set_vals)
we do not directly retrieve the list of nested objects.
Thus m2i returns an empty... | scapy/asn1fields.py | def m2i(self, pkt, s):
"""
ASN1F_SEQUENCE behaves transparently, with nested ASN1_objects being
dissected one by one. Because we use obj.dissect (see loop below)
instead of obj.m2i (as we trust dissect to do the appropriate set_vals)
we do not directly retrieve the list of nested... | def m2i(self, pkt, s):
"""
ASN1F_SEQUENCE behaves transparently, with nested ASN1_objects being
dissected one by one. Because we use obj.dissect (see loop below)
instead of obj.m2i (as we trust dissect to do the appropriate set_vals)
we do not directly retrieve the list of nested... | [
"ASN1F_SEQUENCE",
"behaves",
"transparently",
"with",
"nested",
"ASN1_objects",
"being",
"dissected",
"one",
"by",
"one",
".",
"Because",
"we",
"use",
"obj",
".",
"dissect",
"(",
"see",
"loop",
"below",
")",
"instead",
"of",
"obj",
".",
"m2i",
"(",
"as",
"... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/asn1fields.py#L344-L375 | [
"def",
"m2i",
"(",
"self",
",",
"pkt",
",",
"s",
")",
":",
"diff_tag",
",",
"s",
"=",
"BER_tagging_dec",
"(",
"s",
",",
"hidden_tag",
"=",
"self",
".",
"ASN1_tag",
",",
"implicit_tag",
"=",
"self",
".",
"implicit_tag",
",",
"explicit_tag",
"=",
"self",... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | ASN1F_CHOICE.m2i | First we have to retrieve the appropriate choice.
Then we extract the field/packet, according to this choice. | scapy/asn1fields.py | def m2i(self, pkt, s):
"""
First we have to retrieve the appropriate choice.
Then we extract the field/packet, according to this choice.
"""
if len(s) == 0:
raise ASN1_Error("ASN1F_CHOICE: got empty string")
_, s = BER_tagging_dec(s, hidden_tag=self.ASN1_tag,
... | def m2i(self, pkt, s):
"""
First we have to retrieve the appropriate choice.
Then we extract the field/packet, according to this choice.
"""
if len(s) == 0:
raise ASN1_Error("ASN1F_CHOICE: got empty string")
_, s = BER_tagging_dec(s, hidden_tag=self.ASN1_tag,
... | [
"First",
"we",
"have",
"to",
"retrieve",
"the",
"appropriate",
"choice",
".",
"Then",
"we",
"extract",
"the",
"field",
"/",
"packet",
"according",
"to",
"this",
"choice",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/asn1fields.py#L530-L555 | [
"def",
"m2i",
"(",
"self",
",",
"pkt",
",",
"s",
")",
":",
"if",
"len",
"(",
"s",
")",
"==",
"0",
":",
"raise",
"ASN1_Error",
"(",
"\"ASN1F_CHOICE: got empty string\"",
")",
"_",
",",
"s",
"=",
"BER_tagging_dec",
"(",
"s",
",",
"hidden_tag",
"=",
"se... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | IGMP.igmpize | Called to explicitly fixup the packet according to the IGMP RFC
The rules are:
General:
1. the Max Response time is meaningful only in Membership Queries and should be zero
IP:
1. Send General Group Query to 224.0.0.1 (all systems)
2. Send Leave Group to 224... | scapy/contrib/igmp.py | def igmpize(self):
"""Called to explicitly fixup the packet according to the IGMP RFC
The rules are:
General:
1. the Max Response time is meaningful only in Membership Queries and should be zero
IP:
1. Send General Group Query to 224.0.0.1 (all systems)
... | def igmpize(self):
"""Called to explicitly fixup the packet according to the IGMP RFC
The rules are:
General:
1. the Max Response time is meaningful only in Membership Queries and should be zero
IP:
1. Send General Group Query to 224.0.0.1 (all systems)
... | [
"Called",
"to",
"explicitly",
"fixup",
"the",
"packet",
"according",
"to",
"the",
"IGMP",
"RFC"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/igmp.py#L95-L152 | [
"def",
"igmpize",
"(",
"self",
")",
":",
"gaddr",
"=",
"self",
".",
"gaddr",
"if",
"hasattr",
"(",
"self",
",",
"\"gaddr\"",
")",
"and",
"self",
".",
"gaddr",
"else",
"\"0.0.0.0\"",
"# noqa: E501",
"underlayer",
"=",
"self",
".",
"underlayer",
"if",
"sel... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | _bgp_dispatcher | Returns the right class for a given BGP message. | scapy/contrib/bgp.py | def _bgp_dispatcher(payload):
"""
Returns the right class for a given BGP message.
"""
cls = conf.raw_layer
# By default, calling BGP() will build a BGPHeader.
if payload is None:
cls = _get_cls("BGPHeader", conf.raw_layer)
else:
if len(payload) >= _BGP_HEADER_SIZE and\
... | def _bgp_dispatcher(payload):
"""
Returns the right class for a given BGP message.
"""
cls = conf.raw_layer
# By default, calling BGP() will build a BGPHeader.
if payload is None:
cls = _get_cls("BGPHeader", conf.raw_layer)
else:
if len(payload) >= _BGP_HEADER_SIZE and\
... | [
"Returns",
"the",
"right",
"class",
"for",
"a",
"given",
"BGP",
"message",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/bgp.py#L423-L445 | [
"def",
"_bgp_dispatcher",
"(",
"payload",
")",
":",
"cls",
"=",
"conf",
".",
"raw_layer",
"# By default, calling BGP() will build a BGPHeader.",
"if",
"payload",
"is",
"None",
":",
"cls",
"=",
"_get_cls",
"(",
"\"BGPHeader\"",
",",
"conf",
".",
"raw_layer",
")",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | _bgp_capability_dispatcher | Returns the right class for a given BGP capability. | scapy/contrib/bgp.py | def _bgp_capability_dispatcher(payload):
"""
Returns the right class for a given BGP capability.
"""
cls = _capabilities_registry["BGPCapGeneric"]
# By default, calling BGPCapability() will build a "generic" capability.
if payload is None:
cls = _capabilities_registry["BGPCapGeneric"]
... | def _bgp_capability_dispatcher(payload):
"""
Returns the right class for a given BGP capability.
"""
cls = _capabilities_registry["BGPCapGeneric"]
# By default, calling BGPCapability() will build a "generic" capability.
if payload is None:
cls = _capabilities_registry["BGPCapGeneric"]
... | [
"Returns",
"the",
"right",
"class",
"for",
"a",
"given",
"BGP",
"capability",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/bgp.py#L551-L568 | [
"def",
"_bgp_capability_dispatcher",
"(",
"payload",
")",
":",
"cls",
"=",
"_capabilities_registry",
"[",
"\"BGPCapGeneric\"",
"]",
"# By default, calling BGPCapability() will build a \"generic\" capability.",
"if",
"payload",
"is",
"None",
":",
"cls",
"=",
"_capabilities_reg... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | BGPFieldIPv4.i2m | Internal" (IP as bytes, mask as int) to "machine"
representation. | scapy/contrib/bgp.py | def i2m(self, pkt, i):
""""Internal" (IP as bytes, mask as int) to "machine"
representation."""
mask, ip = i
ip = socket.inet_aton(ip)
return struct.pack(">B", mask) + ip[:self.mask2iplen(mask)] | def i2m(self, pkt, i):
""""Internal" (IP as bytes, mask as int) to "machine"
representation."""
mask, ip = i
ip = socket.inet_aton(ip)
return struct.pack(">B", mask) + ip[:self.mask2iplen(mask)] | [
"Internal",
"(",
"IP",
"as",
"bytes",
"mask",
"as",
"int",
")",
"to",
"machine",
"representation",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/bgp.py#L129-L134 | [
"def",
"i2m",
"(",
"self",
",",
"pkt",
",",
"i",
")",
":",
"mask",
",",
"ip",
"=",
"i",
"ip",
"=",
"socket",
".",
"inet_aton",
"(",
"ip",
")",
"return",
"struct",
".",
"pack",
"(",
"\">B\"",
",",
"mask",
")",
"+",
"ip",
"[",
":",
"self",
".",... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | BGPFieldIPv6.i2m | Internal" (IP as bytes, mask as int) to "machine" representation. | scapy/contrib/bgp.py | def i2m(self, pkt, i):
""""Internal" (IP as bytes, mask as int) to "machine" representation.""" # noqa: E501
mask, ip = i
ip = pton_ntop.inet_pton(socket.AF_INET6, ip)
return struct.pack(">B", mask) + ip[:self.mask2iplen(mask)] | def i2m(self, pkt, i):
""""Internal" (IP as bytes, mask as int) to "machine" representation.""" # noqa: E501
mask, ip = i
ip = pton_ntop.inet_pton(socket.AF_INET6, ip)
return struct.pack(">B", mask) + ip[:self.mask2iplen(mask)] | [
"Internal",
"(",
"IP",
"as",
"bytes",
"mask",
"as",
"int",
")",
"to",
"machine",
"representation",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/bgp.py#L174-L178 | [
"def",
"i2m",
"(",
"self",
",",
"pkt",
",",
"i",
")",
":",
"# noqa: E501",
"mask",
",",
"ip",
"=",
"i",
"ip",
"=",
"pton_ntop",
".",
"inet_pton",
"(",
"socket",
".",
"AF_INET6",
",",
"ip",
")",
"return",
"struct",
".",
"pack",
"(",
"\">B\"",
",",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | BGPCapability.pre_dissect | Check that the payload is long enough (at least 2 bytes). | scapy/contrib/bgp.py | def pre_dissect(self, s):
"""
Check that the payload is long enough (at least 2 bytes).
"""
length = len(s)
if length < _BGP_CAPABILITY_MIN_SIZE:
err = " ({}".format(length) + " is < _BGP_CAPABILITY_MIN_SIZE "
err += "({})).".format(_BGP_CAPABILITY_MIN_SIZ... | def pre_dissect(self, s):
"""
Check that the payload is long enough (at least 2 bytes).
"""
length = len(s)
if length < _BGP_CAPABILITY_MIN_SIZE:
err = " ({}".format(length) + " is < _BGP_CAPABILITY_MIN_SIZE "
err += "({})).".format(_BGP_CAPABILITY_MIN_SIZ... | [
"Check",
"that",
"the",
"payload",
"is",
"long",
"enough",
"(",
"at",
"least",
"2",
"bytes",
")",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/bgp.py#L596-L605 | [
"def",
"pre_dissect",
"(",
"self",
",",
"s",
")",
":",
"length",
"=",
"len",
"(",
"s",
")",
"if",
"length",
"<",
"_BGP_CAPABILITY_MIN_SIZE",
":",
"err",
"=",
"\" ({}\"",
".",
"format",
"(",
"length",
")",
"+",
"\" is < _BGP_CAPABILITY_MIN_SIZE \"",
"err",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | ISOTPHeader.post_build | This will set the ByteField 'length' to the correct value. | scapy/contrib/isotp.py | def post_build(self, pkt, pay):
"""
This will set the ByteField 'length' to the correct value.
"""
if self.length is None:
pkt = pkt[:4] + chb(len(pay)) + pkt[5:]
return pkt + pay | def post_build(self, pkt, pay):
"""
This will set the ByteField 'length' to the correct value.
"""
if self.length is None:
pkt = pkt[:4] + chb(len(pay)) + pkt[5:]
return pkt + pay | [
"This",
"will",
"set",
"the",
"ByteField",
"length",
"to",
"the",
"correct",
"value",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/isotp.py#L200-L206 | [
"def",
"post_build",
"(",
"self",
",",
"pkt",
",",
"pay",
")",
":",
"if",
"self",
".",
"length",
"is",
"None",
":",
"pkt",
"=",
"pkt",
"[",
":",
"4",
"]",
"+",
"chb",
"(",
"len",
"(",
"pay",
")",
")",
"+",
"pkt",
"[",
"5",
":",
"]",
"return... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | ISOTPHeader.guess_payload_class | ISOTP encodes the frame type in the first nibble of a frame. | scapy/contrib/isotp.py | def guess_payload_class(self, payload):
"""
ISOTP encodes the frame type in the first nibble of a frame.
"""
t = (orb(payload[0]) & 0xf0) >> 4
if t == 0:
return ISOTP_SF
elif t == 1:
return ISOTP_FF
elif t == 2:
return ISOTP_CF
... | def guess_payload_class(self, payload):
"""
ISOTP encodes the frame type in the first nibble of a frame.
"""
t = (orb(payload[0]) & 0xf0) >> 4
if t == 0:
return ISOTP_SF
elif t == 1:
return ISOTP_FF
elif t == 2:
return ISOTP_CF
... | [
"ISOTP",
"encodes",
"the",
"frame",
"type",
"in",
"the",
"first",
"nibble",
"of",
"a",
"frame",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/isotp.py#L208-L220 | [
"def",
"guess_payload_class",
"(",
"self",
",",
"payload",
")",
":",
"t",
"=",
"(",
"orb",
"(",
"payload",
"[",
"0",
"]",
")",
"&",
"0xf0",
")",
">>",
"4",
"if",
"t",
"==",
"0",
":",
"return",
"ISOTP_SF",
"elif",
"t",
"==",
"1",
":",
"return",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | ISOTPMessageBuilder.feed | Attempt to feed an incoming CAN frame into the state machine | scapy/contrib/isotp.py | def feed(self, can):
"""Attempt to feed an incoming CAN frame into the state machine"""
if not isinstance(can, CAN):
raise Scapy_Exception("argument is not a CAN frame")
identifier = can.identifier
data = bytes(can.data)
if len(data) > 1 and self.use_ext_addr is not ... | def feed(self, can):
"""Attempt to feed an incoming CAN frame into the state machine"""
if not isinstance(can, CAN):
raise Scapy_Exception("argument is not a CAN frame")
identifier = can.identifier
data = bytes(can.data)
if len(data) > 1 and self.use_ext_addr is not ... | [
"Attempt",
"to",
"feed",
"an",
"incoming",
"CAN",
"frame",
"into",
"the",
"state",
"machine"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/isotp.py#L329-L340 | [
"def",
"feed",
"(",
"self",
",",
"can",
")",
":",
"if",
"not",
"isinstance",
"(",
"can",
",",
"CAN",
")",
":",
"raise",
"Scapy_Exception",
"(",
"\"argument is not a CAN frame\"",
")",
"identifier",
"=",
"can",
".",
"identifier",
"data",
"=",
"bytes",
"(",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | ISOTPMessageBuilder.pop | Returns a built ISOTP message
:param identifier: if not None, only return isotp messages with this
destination
:param ext_addr: if identifier is not None, only return isotp messages
with this extended address for destination
:param basecls: the... | scapy/contrib/isotp.py | def pop(self, identifier=None, ext_addr=None, basecls=ISOTP):
"""
Returns a built ISOTP message
:param identifier: if not None, only return isotp messages with this
destination
:param ext_addr: if identifier is not None, only return isotp messages
... | def pop(self, identifier=None, ext_addr=None, basecls=ISOTP):
"""
Returns a built ISOTP message
:param identifier: if not None, only return isotp messages with this
destination
:param ext_addr: if identifier is not None, only return isotp messages
... | [
"Returns",
"a",
"built",
"ISOTP",
"message",
":",
"param",
"identifier",
":",
"if",
"not",
"None",
"only",
"return",
"isotp",
"messages",
"with",
"this",
"destination",
":",
"param",
"ext_addr",
":",
"if",
"identifier",
"is",
"not",
"None",
"only",
"return",... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/isotp.py#L347-L370 | [
"def",
"pop",
"(",
"self",
",",
"identifier",
"=",
"None",
",",
"ext_addr",
"=",
"None",
",",
"basecls",
"=",
"ISOTP",
")",
":",
"if",
"identifier",
"is",
"not",
"None",
":",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"self",
".",
"ready",
")",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | ISOTPSoftSocket.begin_send | Begin the transmission of message p. This method returns after
sending the first frame. If multiple frames are necessary to send the
message, this socket will unable to send other messages until either
the transmission of this frame succeeds or it fails. | scapy/contrib/isotp.py | def begin_send(self, p):
"""Begin the transmission of message p. This method returns after
sending the first frame. If multiple frames are necessary to send the
message, this socket will unable to send other messages until either
the transmission of this frame succeeds or it fails."""
... | def begin_send(self, p):
"""Begin the transmission of message p. This method returns after
sending the first frame. If multiple frames are necessary to send the
message, this socket will unable to send other messages until either
the transmission of this frame succeeds or it fails."""
... | [
"Begin",
"the",
"transmission",
"of",
"message",
"p",
".",
"This",
"method",
"returns",
"after",
"sending",
"the",
"first",
"frame",
".",
"If",
"multiple",
"frames",
"are",
"necessary",
"to",
"send",
"the",
"message",
"this",
"socket",
"will",
"unable",
"to"... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/isotp.py#L602-L610 | [
"def",
"begin_send",
"(",
"self",
",",
"p",
")",
":",
"if",
"hasattr",
"(",
"p",
",",
"\"sent_time\"",
")",
":",
"p",
".",
"sent_time",
"=",
"time",
".",
"time",
"(",
")",
"return",
"self",
".",
"outs",
".",
"begin_send",
"(",
"bytes",
"(",
"p",
... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | ISOTPSoftSocket.recv_with_timeout | Receive a complete ISOTP message, blocking until a message is
received or the specified timeout is reached.
If timeout is 0, then this function doesn't block and returns the
first frame in the receive buffer or None if there isn't any. | scapy/contrib/isotp.py | def recv_with_timeout(self, timeout=1):
"""Receive a complete ISOTP message, blocking until a message is
received or the specified timeout is reached.
If timeout is 0, then this function doesn't block and returns the
first frame in the receive buffer or None if there isn't any."""
... | def recv_with_timeout(self, timeout=1):
"""Receive a complete ISOTP message, blocking until a message is
received or the specified timeout is reached.
If timeout is 0, then this function doesn't block and returns the
first frame in the receive buffer or None if there isn't any."""
... | [
"Receive",
"a",
"complete",
"ISOTP",
"message",
"blocking",
"until",
"a",
"message",
"is",
"received",
"or",
"the",
"specified",
"timeout",
"is",
"reached",
".",
"If",
"timeout",
"is",
"0",
"then",
"this",
"function",
"doesn",
"t",
"block",
"and",
"returns",... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/isotp.py#L612-L621 | [
"def",
"recv_with_timeout",
"(",
"self",
",",
"timeout",
"=",
"1",
")",
":",
"msg",
"=",
"self",
".",
"ins",
".",
"recv",
"(",
"timeout",
")",
"t",
"=",
"time",
".",
"time",
"(",
")",
"if",
"msg",
"is",
"None",
":",
"raise",
"Scapy_Exception",
"(",... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | ISOTPSoftSocket.recv_raw | Receive a complete ISOTP message, blocking until a message is
received or the specified timeout is reached.
If self.timeout is 0, then this function doesn't block and returns the
first frame in the receive buffer or None if there isn't any. | scapy/contrib/isotp.py | def recv_raw(self, x=0xffff):
"""Receive a complete ISOTP message, blocking until a message is
received or the specified timeout is reached.
If self.timeout is 0, then this function doesn't block and returns the
first frame in the receive buffer or None if there isn't any."""
msg... | def recv_raw(self, x=0xffff):
"""Receive a complete ISOTP message, blocking until a message is
received or the specified timeout is reached.
If self.timeout is 0, then this function doesn't block and returns the
first frame in the receive buffer or None if there isn't any."""
msg... | [
"Receive",
"a",
"complete",
"ISOTP",
"message",
"blocking",
"until",
"a",
"message",
"is",
"received",
"or",
"the",
"specified",
"timeout",
"is",
"reached",
".",
"If",
"self",
".",
"timeout",
"is",
"0",
"then",
"this",
"function",
"doesn",
"t",
"block",
"a... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/isotp.py#L623-L630 | [
"def",
"recv_raw",
"(",
"self",
",",
"x",
"=",
"0xffff",
")",
":",
"msg",
"=",
"self",
".",
"ins",
".",
"recv",
"(",
")",
"t",
"=",
"time",
".",
"time",
"(",
")",
"return",
"self",
".",
"basecls",
",",
"msg",
",",
"t"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | ISOTPSoftSocket.select | This function is called during sendrecv() routine to wait for
sockets to be ready to receive | scapy/contrib/isotp.py | def select(sockets, remain=None):
"""This function is called during sendrecv() routine to wait for
sockets to be ready to receive
"""
blocking = remain is None or remain > 0
def find_ready_sockets():
return list(filter(lambda x: not x.ins.rx_queue.empty(), sockets))
... | def select(sockets, remain=None):
"""This function is called during sendrecv() routine to wait for
sockets to be ready to receive
"""
blocking = remain is None or remain > 0
def find_ready_sockets():
return list(filter(lambda x: not x.ins.rx_queue.empty(), sockets))
... | [
"This",
"function",
"is",
"called",
"during",
"sendrecv",
"()",
"routine",
"to",
"wait",
"for",
"sockets",
"to",
"be",
"ready",
"to",
"receive"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/isotp.py#L646-L678 | [
"def",
"select",
"(",
"sockets",
",",
"remain",
"=",
"None",
")",
":",
"blocking",
"=",
"remain",
"is",
"None",
"or",
"remain",
">",
"0",
"def",
"find_ready_sockets",
"(",
")",
":",
"return",
"list",
"(",
"filter",
"(",
"lambda",
"x",
":",
"not",
"x"... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | TimeoutThread.set_timeout | Call 'callback' in 'timeout' seconds, unless cancelled. | scapy/contrib/isotp.py | def set_timeout(self, timeout, callback):
"""Call 'callback' in 'timeout' seconds, unless cancelled."""
if not self._ready_sem.acquire(False):
raise Scapy_Exception("Timer was already started")
self._callback = callback
self._timeout = timeout
self._cancelled.clear()... | def set_timeout(self, timeout, callback):
"""Call 'callback' in 'timeout' seconds, unless cancelled."""
if not self._ready_sem.acquire(False):
raise Scapy_Exception("Timer was already started")
self._callback = callback
self._timeout = timeout
self._cancelled.clear()... | [
"Call",
"callback",
"in",
"timeout",
"seconds",
"unless",
"cancelled",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/isotp.py#L791-L799 | [
"def",
"set_timeout",
"(",
"self",
",",
"timeout",
",",
"callback",
")",
":",
"if",
"not",
"self",
".",
"_ready_sem",
".",
"acquire",
"(",
"False",
")",
":",
"raise",
"Scapy_Exception",
"(",
"\"Timer was already started\"",
")",
"self",
".",
"_callback",
"="... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | TimeoutThread.cancel | Stop the timer without executing the callback. | scapy/contrib/isotp.py | def cancel(self):
"""Stop the timer without executing the callback."""
self._cancelled.set()
if not self._dead:
self._ready_sem.acquire()
self._ready_sem.release() | def cancel(self):
"""Stop the timer without executing the callback."""
self._cancelled.set()
if not self._dead:
self._ready_sem.acquire()
self._ready_sem.release() | [
"Stop",
"the",
"timer",
"without",
"executing",
"the",
"callback",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/isotp.py#L801-L806 | [
"def",
"cancel",
"(",
"self",
")",
":",
"self",
".",
"_cancelled",
".",
"set",
"(",
")",
"if",
"not",
"self",
".",
"_dead",
":",
"self",
".",
"_ready_sem",
".",
"acquire",
"(",
")",
"self",
".",
"_ready_sem",
".",
"release",
"(",
")"
] | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | TimeoutThread.stop | Stop the thread, making this object unusable. | scapy/contrib/isotp.py | def stop(self):
"""Stop the thread, making this object unusable."""
if not self._dead:
self._killed = True
self._cancelled.set()
self._busy_sem.release()
self.join()
if not self._ready_sem.acquire(False):
warning("ISOTP Timer th... | def stop(self):
"""Stop the thread, making this object unusable."""
if not self._dead:
self._killed = True
self._cancelled.set()
self._busy_sem.release()
self.join()
if not self._ready_sem.acquire(False):
warning("ISOTP Timer th... | [
"Stop",
"the",
"thread",
"making",
"this",
"object",
"unusable",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/isotp.py#L808-L817 | [
"def",
"stop",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_dead",
":",
"self",
".",
"_killed",
"=",
"True",
"self",
".",
"_cancelled",
".",
"set",
"(",
")",
"self",
".",
"_busy_sem",
".",
"release",
"(",
")",
"self",
".",
"join",
"(",
")",... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | ISOTPSocketImplementation._rx_timer_handler | Method called every time the rx_timer times out, due to the peer not
sending a consecutive frame within the expected time window | scapy/contrib/isotp.py | def _rx_timer_handler(self):
"""Method called every time the rx_timer times out, due to the peer not
sending a consecutive frame within the expected time window"""
with self.rx_mutex:
if self.rx_state == ISOTP_WAIT_DATA:
# we did not get new data frames in time.
... | def _rx_timer_handler(self):
"""Method called every time the rx_timer times out, due to the peer not
sending a consecutive frame within the expected time window"""
with self.rx_mutex:
if self.rx_state == ISOTP_WAIT_DATA:
# we did not get new data frames in time.
... | [
"Method",
"called",
"every",
"time",
"the",
"rx_timer",
"times",
"out",
"due",
"to",
"the",
"peer",
"not",
"sending",
"a",
"consecutive",
"frame",
"within",
"the",
"expected",
"time",
"window"
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/isotp.py#L959-L968 | [
"def",
"_rx_timer_handler",
"(",
"self",
")",
":",
"with",
"self",
".",
"rx_mutex",
":",
"if",
"self",
".",
"rx_state",
"==",
"ISOTP_WAIT_DATA",
":",
"# we did not get new data frames in time.",
"# reset rx state",
"self",
".",
"rx_state",
"=",
"ISOTP_IDLE",
"warnin... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | ISOTPSocketImplementation._tx_timer_handler | Method called every time the tx_timer times out, which can happen in
two situations: either a Flow Control frame was not received in time,
or the Separation Time Min is expired and a new frame must be sent. | scapy/contrib/isotp.py | def _tx_timer_handler(self):
"""Method called every time the tx_timer times out, which can happen in
two situations: either a Flow Control frame was not received in time,
or the Separation Time Min is expired and a new frame must be sent."""
with self.tx_mutex:
if (self.tx_s... | def _tx_timer_handler(self):
"""Method called every time the tx_timer times out, which can happen in
two situations: either a Flow Control frame was not received in time,
or the Separation Time Min is expired and a new frame must be sent."""
with self.tx_mutex:
if (self.tx_s... | [
"Method",
"called",
"every",
"time",
"the",
"tx_timer",
"times",
"out",
"which",
"can",
"happen",
"in",
"two",
"situations",
":",
"either",
"a",
"Flow",
"Control",
"frame",
"was",
"not",
"received",
"in",
"time",
"or",
"the",
"Separation",
"Time",
"Min",
"... | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/isotp.py#L970-L1018 | [
"def",
"_tx_timer_handler",
"(",
"self",
")",
":",
"with",
"self",
".",
"tx_mutex",
":",
"if",
"(",
"self",
".",
"tx_state",
"==",
"ISOTP_WAIT_FC",
"or",
"self",
".",
"tx_state",
"==",
"ISOTP_WAIT_FIRST_FC",
")",
":",
"# we did not get any flow control frame in ti... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
train | ISOTPSocketImplementation.on_recv | Function that must be called every time a CAN frame is received, to
advance the state machine. | scapy/contrib/isotp.py | def on_recv(self, cf):
"""Function that must be called every time a CAN frame is received, to
advance the state machine."""
data = bytes(cf.data)
if len(data) < 2:
return
ae = 0
if self.extended_rx_addr is not None:
ae = 1
if len(dat... | def on_recv(self, cf):
"""Function that must be called every time a CAN frame is received, to
advance the state machine."""
data = bytes(cf.data)
if len(data) < 2:
return
ae = 0
if self.extended_rx_addr is not None:
ae = 1
if len(dat... | [
"Function",
"that",
"must",
"be",
"called",
"every",
"time",
"a",
"CAN",
"frame",
"is",
"received",
"to",
"advance",
"the",
"state",
"machine",
"."
] | secdev/scapy | python | https://github.com/secdev/scapy/blob/3ffe757c184017dd46464593a8f80f85abc1e79a/scapy/contrib/isotp.py#L1020-L1050 | [
"def",
"on_recv",
"(",
"self",
",",
"cf",
")",
":",
"data",
"=",
"bytes",
"(",
"cf",
".",
"data",
")",
"if",
"len",
"(",
"data",
")",
"<",
"2",
":",
"return",
"ae",
"=",
"0",
"if",
"self",
".",
"extended_rx_addr",
"is",
"not",
"None",
":",
"ae"... | 3ffe757c184017dd46464593a8f80f85abc1e79a |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.