self._serialize_signature_packet_target(target=x)
for x in target)
- def _serialize_signature_packet(self):
+ def _serialize_hashed_signature_packet(self):
if self['signature-version'] != 4:
raise NotImplementedError(
'signature packet version {}'.format(
self['signature-version']))
- signature_version = bytes([self['signature-version']])
- chunks = [signature_version]
+ chunks = [bytes([self['signature-version']])]
chunks.append(bytes([self._reverse(
self._signature_types, self['signature-type'])]))
chunks.append(bytes([self._reverse(
self['hashed-subpackets'])
chunks.append(_struct.pack('>H', len(hashed_subpackets)))
chunks.append(hashed_subpackets)
- hashed_signature_data = b''.join(chunks)
- unhashed_subpackets = self._serialize_signature_subpackets(
- self['unhashed-subpackets'])
- chunks.append(_struct.pack('>H', len(unhashed_subpackets)))
- chunks.append(unhashed_subpackets)
+ return b''.join(chunks)
+
+ def _signature_packet_signed_data(self, hashed_signature_data):
target = self._serialize_signature_packet_target(target=self['target'])
- signed_data = b''.join([
+ return b''.join([
target,
hashed_signature_data,
- signature_version,
+ bytes([self['signature-version']]),
b'\xff',
_struct.pack('>I', len(hashed_signature_data)),
])
+
+ def _serialize_signature_packet(self):
+ hashed_signature_data = self._serialize_hashed_signature_packet()
+ chunks = [hashed_signature_data]
+ unhashed_subpackets = self._serialize_signature_subpackets(
+ self['unhashed-subpackets'])
+ chunks.append(_struct.pack('>H', len(unhashed_subpackets)))
+ chunks.append(unhashed_subpackets)
+ signed_data = self._signature_packet_signed_data(
+ hashed_signature_data=hashed_signature_data)
digest, signature = self.key.sign(
data=signed_data, hash_algorithm=self['hash-algorithm'],
signature_algorithm=self['public-key-algorithm'])