def generate_request(self, context=None):
        base_request = self.generate_base_request()

        if self.is_client:
            if not self._digest_offset_extractor:
                return base_request
        else:
            scheme = self.discover_client_scheme(context)
            if scheme is None:
                return base_request

        # truncate, to leave space for digest
        request = buffer(base_request, 0, self.packet_bytes - 32)

        # get digest offset
        offset = self._digest_offset_extractor(request)

        # calculate digest
        key = self.select_own_key_short()
        digest = _hmac(key, request)

        # insert digest at the offset and return the whole packet
        return request[:offset] + digest + request[offset:]
dataset/ETHPy150Open arkadini/twimp/twimp/crypto/handshake.py/CryptoHandshaker.generate_request/original