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

Class _DictStrField

scapy/contrib/postgres.py:67–85  ·  view source on GitHub ↗

Takes a dictionary as an argument and packs back into a byte string.

Source from the content-addressed store, hash-verified

65
66
67class _DictStrField(StrField):
68 """Takes a dictionary as an argument and packs back into a byte string."""
69
70 def i2m(self, pkt, x):
71 if isinstance(x, bytes):
72 return x
73 if isinstance(x, dict):
74 result = bytes()
75 for k, v in x.items():
76 result += k + b"\x00" + v + b"\x00"
77 return result + b"\x00"
78 else:
79 return super(_DictStrField, self).i2m(pkt, x)
80
81 def i2len(self, pkt, x):
82 # type: (Optional[Packet], Any) -> int
83 if x is None:
84 return 0
85 return len(self.i2m(pkt, x))
86
87
88class Startup(Packet):

Callers 1

StartupClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…