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)
def _callFUT(self, *args, **kw): from webob.util import strings_differ return strings_differ(*args, **kw)
def test_strings_differ(): from webob.util import strings_differ eq_(strings_differ('test1', 'test'), True)