Package dpkt :: Module ah
[hide private]
[frames] | no frames]

Source Code for Module dpkt.ah

 1  # $Id: ah.py 34 2007-01-28 07:54:20Z dugsong $ 
 2  # -*- coding: utf-8 -*- 
 3   
 4  """Authentication Header.""" 
 5  from __future__ import absolute_import 
 6   
 7  from . import dpkt 
 8   
 9   
10 -class AH(dpkt.Packet):
11 """Authentication Header. 12 13 TODO: Longer class information.... 14 15 Attributes: 16 __hdr__: Header fields of AH. 17 auth: Authentication body. 18 data: Message data. 19 """ 20 21 __hdr__ = ( 22 ('nxt', 'B', 0), 23 ('len', 'B', 0), # payload length 24 ('rsvd', 'H', 0), 25 ('spi', 'I', 0), 26 ('seq', 'I', 0) 27 ) 28 auth = b'' 29
30 - def unpack(self, buf):
31 dpkt.Packet.unpack(self, buf) 32 self.auth = self.data[:self.len] 33 buf = self.data[self.len:] 34 from . import ip 35 36 try: 37 self.data = ip.IP.get_proto(self.nxt)(buf) 38 setattr(self, self.data.__class__.__name__.lower(), self.data) 39 except (KeyError, dpkt.UnpackError): 40 self.data = buf
41
42 - def __len__(self):
43 return self.__hdr_len__ + len(self.auth) + len(self.data)
44
45 - def __bytes__(self):
46 return self.pack_hdr() + bytes(self.auth) + bytes(self.data)
47