Example #1
0
 def sign(self, bytes, hash_type="sha256"):
     """Sign some bytes."""
     if hash_type == "sha256":
         return hmac_sha256(self.secret_key, bytes)
     elif hash_type == "sha1":
         return hmac_sha1(self.secret_key, bytes)
     else:
         raise RuntimeError("Unsupported hash type: '%s'" % hash_type)
Example #2
0
 def sign(self, bytes, hash_type="sha256"):
     """Sign some bytes."""
     if hash_type == "sha256":
         return hmac_sha256(self.secret_key, bytes)
     elif hash_type == "sha1":
         return hmac_sha1(self.secret_key, bytes)
     else:
         raise RuntimeError("Unsupported hash type: '%s'" % hash_type)
Example #3
0
    def test_hmac_sha1(self):
        cases = [
            ("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b".decode("hex"),
             "Hi There", "thcxhlUFcmTii8C2+zeMjvFGvgA="),
            ("Jefe", "what do ya want for nothing?",
             "7/zfauXrL6LSdBbV8YTfnCWafHk="),
            ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".decode("hex"),
             "\xdd" * 50, "El1zQrmsEc2Ro5r0iqF7T2PxddM="),
            ]

        for key, data, expected in cases:
            self.assertEqual(hmac_sha1(key, data), expected)
Example #4
0
 def sign(self, bytes, hash_type="sha256"):
     """Sign some bytes."""
     if hash_type == "sha256":
         return hmac_sha256(self.secret_key, bytes)
     elif hash_type == "sha1":
         return hmac_sha1(self.secret_key, bytes)