docs: def parse(self, msg, name):
          """Parses the message.
  
          We check that the message is properly formatted.
  
          :param msg: a json-encoded value containing a JWS or JWE+JWS token
  
          :raises InvalidMessage: if the message cannot be parsed or validated
  
          :returns: A verified payload
          """
  
          try:
              jtok = JWT(jwt=msg)
          except Exception as e:
              raise InvalidMessage('Failed to parse message: %s' % str(e))
  
          try:
              token = jtok.token
              if isinstance(token, JWE):
                  token.decrypt(self.kkstore.server_keys[KEY_USAGE_ENC])
                  # If an encrypted payload is received then there must be
                  # a nested signed payload to verify the provenance.
                  payload = token.payload.decode('utf-8')
                  token = JWS()
                  token.deserialize(payload)
              elif isinstance(token, JWS):
                  pass
              else:
                  raise TypeError("Invalid Token type: %s" % type(jtok))
  
              # Retrieve client keys for later use
              self.client_keys = [
                  JWK(**self._get_key(token.jose_header, KEY_USAGE_SIG)),
                  JWK(**self._get_key(token.jose_header, KEY_USAGE_ENC))]
  
              # verify token and get payload
              token.verify(self.client_keys[KEY_USAGE_SIG])
              claims = json_decode(token.payload)
          except Exception as e:
              logger.debug('Failed to validate message', exc_info=True)
              raise InvalidMessage('Failed to validate message: %s' % str(e))
  
          check_kem_claims(claims, name)
          self.name = name
          self.payload = claims.get('value')
          self.msg_type = 'kem'
  
          return {'type': self.msg_type,
                  'value': {'kid': self.client_keys[KEY_USAGE_ENC].key_id,
                            'claims': claims}}