1## This file is part of Scapy 2## See http://www.secdev.org/projects/scapy for more informations 3## Copyright (C) Philippe Biondi <phil@secdev.org> 4## This program is published under a GPLv2 license 5 6""" 7Packet holding data in Abstract Syntax Notation (ASN.1). 8""" 9 10from __future__ import absolute_import 11from scapy.base_classes import Packet_metaclass 12from scapy.packet import Packet 13import scapy.modules.six as six 14 15class ASN1Packet_metaclass(Packet_metaclass): 16 def __new__(cls, name, bases, dct): 17 if dct["ASN1_root"] is not None: 18 dct["fields_desc"] = dct["ASN1_root"].get_fields_list() 19 return super(ASN1Packet_metaclass, cls).__new__(cls, name, bases, dct) 20 21class ASN1_Packet(six.with_metaclass(ASN1Packet_metaclass, Packet)): 22 ASN1_root = None 23 ASN1_codec = None 24 def self_build(self): 25 if self.raw_packet_cache is not None: 26 return self.raw_packet_cache 27 return self.ASN1_root.build(self) 28 def do_dissect(self, x): 29 return self.ASN1_root.dissect(self, x) 30 31 32