Serialize data structure into string.
(self, data)
| 29 | self._serializer = serializer |
| 30 | |
| 31 | def serialize(self, data): |
| 32 | """Serialize data structure into string.""" |
| 33 | assert self._key is not None |
| 34 | assert self._cert is not None |
| 35 | with reraise_errors('Unable to serialize: {0!r}', (Exception,)): |
| 36 | content_type, content_encoding, body = dumps( |
| 37 | data, serializer=self._serializer) |
| 38 | |
| 39 | # What we sign is the serialized body, not the body itself. |
| 40 | # this way the receiver doesn't have to decode the contents |
| 41 | # to verify the signature (and thus avoiding potential flaws |
| 42 | # in the decoding step). |
| 43 | body = ensure_bytes(body) |
| 44 | return self._pack(body, content_type, content_encoding, |
| 45 | signature=self._key.sign(body, self._digest), |
| 46 | signer=self._cert.get_id()) |
| 47 | |
| 48 | def deserialize(self, data): |
| 49 | """Deserialize data structure from string.""" |