Example #1
0
 def parse_layer(to_parse):
     """
     Takes a given scapy layer object and returns a Geneva Layer object.
     """
     for layer in SUPPORTED_LAYERS:
         if layer.name_matches(to_parse.name):
             return layer(to_parse)
Example #2
0
 def gen_random():
     """
     Generates a possible random protocol, field, and value.
     """
     # layer is a Geneva Layer class - to instantiate it, we must give it a layer
     # to use. Every Geneva Layer stores the underlying scapy layer it wraps,
     # so simply invoke that as a default.
     layer = random.choice(SUPPORTED_LAYERS)
     layer_obj = layer(layer.protocol())
     field, value = layer_obj.gen_random()
     return layer.protocol, field, value
Example #3
0
    def parse(cls, str_protocol, field, value):
        """
        Parses a given value for a given field of a given protocool.

        Raises AssertionError if the protocol is not present.
        """
        parsing_layer = None
        for layer in SUPPORTED_LAYERS:
            if layer.name_matches(str_protocol):
                parsing_layer = layer(None)

        assert parsing_layer, "Given protocol %s is not permitted." % str_protocol

        return parsing_layer.parse(field, value)