"""
return [k for k,v in dict.items() if v == value][0]
+ def copy(self):
+ packet = PGPPacket(key=self.key)
+ packet.update(self)
+ return packet
+
def __str__(self):
method_name = '_str_{}'.format(self._clean_type())
method = getattr(self, method_name, None)
'algorithm-specific key fields for {}'.format(
self['public-key-algorithm']))
fingerprint = _hashlib.sha1()
- fingerprint.update(b'\x99')
- fingerprint.update(_struct.pack('>H', len(data)))
- fingerprint.update(data)
+ fingerprint_target = self
+ if self['type'] != 'public-key packet':
+ fingerprint_target = self.copy()
+ fingerprint_target['type'] = 'public-key packet'
+ fingerprint.update(
+ self._serialize_signature_packet_target(target=fingerprint_target))
self['fingerprint'] = fingerprint.hexdigest()
return offset
self['user'] = str(data, 'utf-8')
def to_bytes(self):
- method_name = '_serialize_{}'.format(self._clean_type())
- method = getattr(self, method_name, None)
- if not method:
- raise NotImplementedError(
- 'cannot serialize packet type {!r}'.format(self['type']))
- body = method()
+ body = self._serialize_body()
+ if body is None:
+ raise ValueError(method)
self['length'] = len(body)
return b''.join([
self._serialize_header(),
length_data,
])
+ def _serialize_body(self):
+ method_name = '_serialize_{}'.format(self._clean_type())
+ method = getattr(self, method_name, None)
+ if not method:
+ raise NotImplementedError(
+ 'cannot serialize packet type {!r}'.format(self['type']))
+ return method()
+
@staticmethod
def _serialize_multiprecision_integer(integer):
r"""Serialize RFC 4880's multipricision integers