class PGPPacket (dict):
# http://tools.ietf.org/search/rfc4880
+ _old_format_packet_length_type = { # type: (bytes, struct type)
+ 0: (1, 'B'), # 1-byte unsigned integer
+ 1: (2, 'H'), # 2-byte unsigned integer
+ 2: (4, 'I'), # 4-byte unsigned integer
+ 3: (None, None),
+ }
+
def from_bytes(self, data):
packet_tag = data[0]
always_one = packet_tag & 1 << 7
self['new-format'] = packet_tag & 1 << 6
if self['new-format']:
self['packet-tag'] = packet_tag & 0b111111
+ raise NotImplementedError('new-format packet length')
else:
self['packet-tag'] = packet_tag >> 2 & 0b1111
self['length-type'] = packet_tag & 0b11
+ length_bytes, length_type = self._old_format_packet_length_type[
+ self['length-type']]
+ if not length_bytes:
+ raise NotImplementedError(
+ 'old-format packet of indeterminate length')
def to_bytes(self):
pass