MCPcopy Create free account
hub / github.com/secdev/scapy / H2PaddedPriorityHeadersFrame

Class H2PaddedPriorityHeadersFrame

scapy/contrib/http2.py:1591–1648  ·  view source on GitHub ↗

H2PaddedPriorityHeadersFrame is the variant of H2HeadersFrame where both priority and padding flags are set

Source from the content-addressed store, hash-verified

1589
1590
1591class H2PaddedPriorityHeadersFrame(H2AbstractHeadersFrame):
1592 """ H2PaddedPriorityHeadersFrame is the variant of H2HeadersFrame where
1593 both priority and padding flags are set
1594 """
1595 __slots__ = ['s_len']
1596
1597 name = 'HTTP/2 Headers Frame with Padding and Priority'
1598 fields_desc = [
1599 fields.FieldLenField('padlen', None, length_of='padding', fmt='B'),
1600 fields.BitField('exclusive', 0, 1),
1601 fields.BitField('stream_dependency', 0, 31),
1602 fields.ByteField('weight', 0),
1603 fields.PacketListField('hdrs', [], HPackHeaders,
1604 length_from=lambda pkt: pkt.get_hdrs_len()
1605 ),
1606 fields.StrLenField('padding', '',
1607 length_from=lambda pkt: pkt.getfieldval('padlen')
1608 )
1609 ]
1610
1611 def get_hdrs_len(self):
1612 # type: () -> int
1613 """ get_hdrs_len computes the length of the hdrs field
1614
1615 To do this computation, the length of the padlen field, the priority
1616 information fields and the actual padding is subtracted to the string
1617 that was provided to the pre_dissect fun of the pkt parameter.
1618 :return: int: the length of the hdrs field
1619 :raises: AssertionError
1620 """
1621
1622 padding_len = self.getfieldval('padlen')
1623 fld, fval = self.getfield_and_val('padlen')
1624 padding_len_len = fld.i2len(self, fval)
1625 bit_cnt = self.get_field('exclusive').size
1626 bit_cnt += self.get_field('stream_dependency').size
1627 fld, fval = self.getfield_and_val('weight')
1628 weight_len = fld.i2len(self, fval)
1629 ret = int(self.s_len -
1630 padding_len_len -
1631 padding_len -
1632 (bit_cnt / 8) -
1633 weight_len
1634 )
1635 assert ret >= 0
1636 return ret
1637
1638 def pre_dissect(self, s):
1639 # type: (str) -> str
1640 """pre_dissect is filling the s_len property of this instance. This
1641 property is later used during the parsing of the hdrs PacketListField
1642 when trying to evaluate the length of the PacketListField! This "trick"
1643 works because the underlayer packet (H2Frame) is assumed to override the # noqa: E501
1644 "extract_padding" method and to only provide to this packet the data
1645 necessary for this packet. Tricky, tricky, will break some day probably! # noqa: E501
1646 """
1647 self.s_len = len(s)
1648 return s

Callers

nothing calls this directly

Calls 2

get_hdrs_lenMethod · 0.45
getfieldvalMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…