Пример #1
0
    def loads(self, bstruct):
        """
        Given a ``bstruct`` (a bytestring), verify the signature and then
        deserialize and return the deserialized value.

        A ``ValueError`` will be raised if the signature fails to validate.
        """
        try:
            b64padding = b"=" * (-len(bstruct) % 4)
            fstruct = base64.urlsafe_b64decode(bytes_(bstruct) + b64padding)
        except (binascii.Error, TypeError) as e:
            raise ValueError("Badly formed base64 data: %s" % e)

        cstruct = fstruct[self.digest_size :]
        expected_sig = fstruct[: self.digest_size]

        sig = hmac.new(self.salted_secret, bytes_(cstruct), self.digestmod).digest()

        if strings_differ(sig, expected_sig):
            raise ValueError("Invalid signature")

        return self.serializer.loads(cstruct)
Пример #2
0
    def loads(self, bstruct):
        """
        Given a ``bstruct`` (a bytestring), verify the signature and then
        deserialize and return the deserialized value.

        A ``ValueError`` will be raised if the signature fails to validate.
        """
        try:
            b64padding = b"=" * (-len(bstruct) % 4)
            fstruct = base64.urlsafe_b64decode(bytes_(bstruct) + b64padding)
        except (binascii.Error, TypeError) as e:
            raise ValueError("Badly formed base64 data: %s" % e)

        cstruct = fstruct[self.digest_size :]
        expected_sig = fstruct[: self.digest_size]

        sig = hmac.new(self.salted_secret, bytes_(cstruct), self.digestmod).digest()

        if strings_differ(sig, expected_sig):
            raise ValueError("Invalid signature")

        return self.serializer.loads(cstruct)
Пример #3
0
 def _callFUT(self, *args, **kw):
     from webob.util import strings_differ
     return strings_differ(*args, **kw)
Пример #4
0
def test_strings_differ():
    from webob.util import strings_differ

    eq_(strings_differ('test1', 'test'), True)
Пример #5
0
    def _callFUT(self, *args, **kw):
        from webob.util import strings_differ

        return strings_differ(*args, **kw)
Пример #6
0
def test_strings_differ():
    from webob.util import strings_differ

    eq_(strings_differ('test1', 'test'), True)