MCPcopy Index your code
hub / github.com/secdev/scapy / randval

Method randval

scapy/fields.py:286–306  ·  view source on GitHub ↗

Return a volatile object whose value is both random and suitable for this field

(self)

Source from the content-addressed store, hash-verified

284 return copy.copy(self)
285
286 def randval(self):
287 # type: () -> VolatileValue[Any]
288 """Return a volatile object whose value is both random and suitable for this field""" # noqa: E501
289 fmtt = self.fmt[-1]
290 if fmtt in "BbHhIiQq":
291 return {"B": RandByte, "b": RandSByte,
292 "H": RandShort, "h": RandSShort,
293 "I": RandInt, "i": RandSInt,
294 "Q": RandLong, "q": RandSLong}[fmtt]()
295 elif fmtt == "s":
296 if self.fmt[0] in "0123456789":
297 value = int(self.fmt[:-1])
298 else:
299 value = int(self.fmt[1:-1])
300 return RandBin(value)
301 else:
302 raise ValueError(
303 "no random class for [%s] (fmt=%s)." % (
304 self.name, self.fmt
305 )
306 )
307
308
309class _FieldContainer(object):

Callers 2

randvalMethod · 0.45
fuzzFunction · 0.45

Calls 1

RandBinClass · 0.90

Tested by

no test coverage detected