def decode(self): """Deserialize the message body, returning the original python structure sent by the publisher.""" return decode(self.body, self.content_type, self.content_encoding, accept=self.accept)
def deserialize(self, data): """deserialize data structure from string""" assert self._cert_store is not None with reraise_errors("Unable to deserialize: {0!r}", (Exception,)): payload = self._unpack(data) signature, signer, body = (payload["signature"], payload["signer"], payload["body"]) self._cert_store[signer].verify(body, signature, self._digest) return decode(body, payload["content_type"], payload["content_encoding"], force=True)
def deserialize(self, data): """deserialize data structure from string""" assert self._cert_store is not None with reraise_errors('Unable to deserialize: {0!r}', (Exception, )): payload = self._unpack(data) signature, signer, body = (payload['signature'], payload['signer'], payload['body']) self._cert_store[signer].verify(body, signature, self._digest) return decode(bytes_to_str(body), payload['content_type'], payload['content_encoding'], force=True)
def deserialize(self, data): """deserialize data structure from string""" assert self._cert_store is not None with reraise_errors('Unable to deserialize: {0!r}', (Exception, )): payload = self._unpack(data) signature, signer, body = (payload['signature'], payload['signer'], payload['body']) self._cert_store[signer].verify(body, signature, self._digest) return decode(bytes_to_str(body), payload['content_type'], payload['content_encoding'], force=True)
def deserialize(self, data): """deserialize data structure from string""" assert self._cert_store is not None with reraise_errors("Unable to deserialize: %r", (Exception, )): payload = self._unpack(data) signature, signer, body = (payload["signature"], payload["signer"], payload["body"]) self._cert_store[signer].verify(body, signature, self._digest) return decode(body, payload["content_type"], payload["content_encoding"], force=True)
def decode(self, payload): payload = is_py3k and payload or str(payload) return serialization.decode(payload, content_type=self.content_type, content_encoding=self.content_encoding)
def test_register_msgpack__no_msgpack(self): register_msgpack() with self.assertRaises(SerializerNotInstalled): decode('foo', 'application/x-msgpack', 'utf-8')
def test_register_yaml__no_yaml(self): register_yaml() with self.assertRaises(SerializerNotInstalled): decode("foo", "application/x-yaml", "utf-8")
except Exception, exc: raise SecurityError("Unable to serialize: %r" % (exc, )) def deserialize(self, data): """deserialize data structure from string""" assert self._cert_store is not None try: payload = self._unpack(data) signature, signer, body = (payload["signature"], payload["signer"], payload["body"]) self._cert_store[signer].verify(body, signature, self._digest) except Exception, exc: raise SecurityError("Unable to deserialize: %r" % (exc, )) return decode(body, payload["content_type"], payload["content_encoding"], force=True) def _pack(self, body, content_type, content_encoding, signer, signature, sep='\x00\x01'): return b64encode( sep.join([signer, signature, content_type, content_encoding, body])) def _unpack(self, payload,
def test_register_yaml__no_yaml(self): register_yaml() with self.assertRaises(SerializerNotInstalled): decode('foo', 'application/x-yaml', 'utf-8')
def test_register_msgpack__no_msgpack(self): register_msgpack() with self.assertRaises(SerializerNotInstalled): decode('foo', 'application/x-msgpack', 'utf-8')
def decode(self, payload): payload = PY3 and payload or str(payload) return decode(payload, content_type=self.content_type, content_encoding=self.content_encoding, accept=self.accept)
def decode(self, payload): payload = PY3 and payload or str(payload) return decode(payload, content_type=self.content_type, content_encoding=self.content_encoding, accept=self.accept)
def test_register_yaml__no_yaml(self): register_yaml() with self.assertRaises(SerializerNotInstalled): decode('foo', 'application/x-yaml', 'utf-8')
def decode(self, payload): payload = PY3 and payload or str(payload) return serialization.decode(payload, content_type=self.content_type, content_encoding=self.content_encoding)
def deserialize(self, data): """deserialize data structure from string""" assert self._cert_store is not None try: payload = self._unpack(data) signature, signer, body = (payload["signature"], payload["signer"], payload["body"]) self._cert_store[signer].verify(body, signature, self._digest) except Exception, exc: raise SecurityError, SecurityError( "Unable to deserialize: %r" % (exc, )), sys.exc_info()[2] return decode(body, payload["content_type"], payload["content_encoding"], force=True) def _pack(self, body, content_type, content_encoding, signer, signature, sep='\x00\x01'): return b64encode(sep.join([signer, signature, content_type, content_encoding, body])) def _unpack(self, payload, sep='\x00\x01', fields=("signer", "signature", "content_type", "content_encoding", "body")): return dict(zip(fields, b64decode(payload).split(sep))) def register_auth(key=None, cert=None, store=None, digest="sha1", serializer="json"): """register security serializer"""
def test_register_msgpack__no_msgpack(self): register_msgpack() with self.assertRaises(SerializerNotInstalled): decode("foo", "application/x-msgpack", "utf-8")
def test_register_msgpack__no_msgpack(self): register_msgpack() with self.assertRaises(SerializerNotInstalled): decode("foo", "application/x-msgpack", "utf-8")
def test_register_yaml__no_yaml(self): register_yaml() with self.assertRaises(SerializerNotInstalled): decode("foo", "application/x-yaml", "utf-8")
def decode(self): """Deserialize the message body, returning the original python structure sent by the publisher.""" return decode(self.body, self.content_type, self.content_encoding)
def decode(self, payload): return serialization.decode(str(payload), content_type=self.content_type, content_encoding=self.content_encoding)