else:
key_end = 0
secret_key = decrypted_data[:key_end]
+ secret_offset = 0
if key_end:
secret_key_checksum = decrypted_data[key_end:]
if key_end == -2:
raise ValueError(
'corrupt secret key (checksum {} != expected {})'.format(
secret_key_checksum, calculated_checksum))
- self['secret-key'] = secret_key
+ if self['public-key-algorithm'].startswith('rsa '):
+ o, self['secret-exponent'] = self._parse_multiprecision_integer(
+ secret_key[secret_offset:])
+ secret_offset += o
+ o, self['secret-prime-p'] = self._parse_multiprecision_integer(
+ secret_key[secret_offset:])
+ secret_offset += o
+ o, self['secret-prime-q'] = self._parse_multiprecision_integer(
+ secret_key[secret_offset:])
+ secret_offset += o
+ o, self['secret-inverse-of-p-mod-q'] = (
+ self._parse_multiprecision_integer(
+ secret_key[secret_offset:]))
+ secret_offset += o
+ elif self['public-key-algorithm'].startswith('dsa '):
+ o, self['secret-exponent'] = self._parse_multiprecision_integer(
+ secret_key[secret_offset:])
+ secret_offset += o
+ elif self['public-key-algorithm'].startswith('elgamal '):
+ o, self['secret-exponent'] = self._parse_multiprecision_integer(
+ secret_key[secret_offset:])
+ secret_offset += o
+ else:
+ raise NotImplementedError(
+ 'algorithm-specific key fields for {}'.format(
+ self['public-key-algorithm']))
+ if secret_offset != len(secret_key):
+ raise ValueError(
+ ('parsed {} out of {} bytes of algorithm-specific key fields '
+ 'for {}').format(
+ secret_offset, len(secret_key),
+ self['public-key-algorithm']))
def _parse_signature_subpackets(self, data):
offset = 0