Esempio n. 1
0
 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)
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
 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)
Esempio n. 5
0
 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)
Esempio n. 6
0
 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)
Esempio n. 7
0
 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")
Esempio n. 9
0
        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,
Esempio n. 10
0
 def test_register_yaml__no_yaml(self):
     register_yaml()
     with self.assertRaises(SerializerNotInstalled):
         decode('foo', 'application/x-yaml', 'utf-8')
Esempio n. 11
0
 def test_register_msgpack__no_msgpack(self):
     register_msgpack()
     with self.assertRaises(SerializerNotInstalled):
         decode('foo', 'application/x-msgpack', 'utf-8')
Esempio n. 12
0
 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)
Esempio n. 13
0
 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)
Esempio n. 14
0
 def test_register_yaml__no_yaml(self):
     register_yaml()
     with self.assertRaises(SerializerNotInstalled):
         decode('foo', 'application/x-yaml', 'utf-8')
Esempio n. 15
0
 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)
Esempio n. 16
0
    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")
Esempio n. 20
0
 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)
Esempio n. 21
0
 def decode(self, payload):
     return serialization.decode(str(payload),
                                 content_type=self.content_type,
                                 content_encoding=self.content_encoding)