docs: def sign_message(self, buf):
          """
          SSH v2 public key authentication is performed.
  
          If the required key is not supported, raise KeyError
          If the signature is invalid, raise ValueError
          """
          key = formats.parse_pubkey(util.read_frame(buf))
          log.debug('looking for %s', key['fingerprint'])
          blob = util.read_frame(buf)
          assert util.read_frame(buf) == b''
          assert not buf.read()
  
          for k in self.conn.parse_public_keys():
              if (k['fingerprint']) == (key['fingerprint']):
                  log.debug('using key %r (%s)', k['name'], k['fingerprint'])
                  key = k
                  break
          else:
              raise KeyError('key not found')
  
          label = key['name'].decode('utf-8')
          log.debug('signing %d-byte blob with "%s" key', len(blob), label)
          try:
              signature = self.conn.sign(blob=blob, identity=key['identity'])
          except IOError:
              return failure()
          log.debug('signature: %r', signature)
  
          try:
              sig_bytes = key['verifier'](sig=signature, msg=blob)
              log.info('signature status: OK')
          except formats.ecdsa.BadSignatureError:
              log.exception('signature status: ERROR')
              raise ValueError('invalid ECDSA signature')
  
          log.debug('signature size: %d bytes', len(sig_bytes))
  
          data = util.frame(util.frame(key['type']), util.frame(sig_bytes))
          code = util.pack('B', msg_code('SSH2_AGENT_SIGN_RESPONSE'))
          return util.frame(code, data)