docs: def _parse_pubkey(stream, packet_type='pubkey'):
      """See https://tools.ietf.org/html/rfc4880#section-5.5 for details."""
      p = {'type': packet_type}
      packet = io.BytesIO()
      with stream.capture(packet):
          p['version'] = stream.readfmt('B')
          p['created'] = stream.readfmt('>L')
          p['algo'] = stream.readfmt('B')
          if p['algo'] in ECDSA_ALGO_IDS:
              log.debug('parsing elliptic curve key')
              # https://tools.ietf.org/html/rfc6637#section-11
              oid_size = stream.readfmt('B')
              oid = stream.read(oid_size)
              assert oid in SUPPORTED_CURVES, util.hexlify(oid)
              p['curve_oid'] = oid
  
              mpi = parse_mpi(stream)
              log.debug('mpi: %x (%d bits)', mpi, mpi.bit_length())
              leftover = stream.read()
              if leftover:
                  leftover = io.BytesIO(leftover)
                  # https://tools.ietf.org/html/rfc6637#section-8
                  # should be b'\x03\x01\x08\x07': SHA256 + AES128
                  size, = util.readfmt(leftover, 'B')
                  p['kdf'] = leftover.read(size)
                  p['secret'] = leftover.read()
  
              parse_func, keygrip_func = SUPPORTED_CURVES[oid]
              keygrip = keygrip_func(parse_func(mpi))
              log.debug('keygrip: %s', util.hexlify(keygrip))
              p['keygrip'] = keygrip
  
          elif p['algo'] == DSA_ALGO_ID:
              parse_mpis(stream, n=4)  # DSA keys are not supported
          elif p['algo'] == ELGAMAL_ALGO_ID:
              parse_mpis(stream, n=3)  # ElGamal keys are not supported
          else:  # assume RSA
              parse_mpis(stream, n=2)  # RSA keys are not supported
          assert not stream.read()
  
      # https://tools.ietf.org/html/rfc4880#section-12.2
      packet_data = packet.getvalue()
      data_to_hash = (b'\x99' + struct.pack('>H', len(packet_data)) +
                      packet_data)
      p['key_id'] = hashlib.sha1(data_to_hash).digest()[-8:]
      p['_to_hash'] = data_to_hash
      log.debug('key ID: %s', util.hexlify(p['key_id']))
      return p