'Serialize data structure into string.'

def serialize(self, data):

    assert (self._key is not None)
    assert (self._cert is not None)
    with reraise_errors(u'Unable    to    serialize:    {0!r}', (Exception,)):
        (content_type, content_encoding, body) = dumps(bytes_to_str(data), serializer=self._serializer)
        body = ensure_bytes(body)
        return self._pack(body, content_type, content_encoding, signature=self._key.sign(body, self._digest), signer=self._cert.get_id())
