summaryrefslogtreecommitdiff
path: root/tests/utils.py
diff options
context:
space:
mode:
authorMark Adams <mark@markadams.me>2015-05-18 23:00:23 -0500
committerMark Adams <mark@markadams.me>2015-05-18 23:13:02 -0500
commit06f461a21102712cfc2139568531c20dc302e79c (patch)
tree54b2189b2139457ccfa27a4598643218ced61169 /tests/utils.py
parent4797f7f10ae78b4a9a2f04023ce45bfa73505735 (diff)
downloadpyjwt-06f461a21102712cfc2139568531c20dc302e79c.tar.gz
Added test vectors from the IETF JOSE Cookbook for HMAC, RSA, and EC.
Diffstat (limited to 'tests/utils.py')
-rw-r--r--tests/utils.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/utils.py b/tests/utils.py
index bf74e78..7722702 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -1,4 +1,5 @@
import os
+import struct
from calendar import timegm
from datetime import datetime
@@ -27,3 +28,23 @@ def utc_timestamp():
def key_path(key_name):
return os.path.join(os.path.dirname(os.path.realpath(__file__)),
'keys', key_name)
+
+# Borrowed from `cryptography`
+if hasattr(int, "from_bytes"):
+ int_from_bytes = int.from_bytes
+else:
+ def int_from_bytes(data, byteorder, signed=False):
+ assert byteorder == 'big'
+ assert not signed
+
+ if len(data) % 4 != 0:
+ data = (b'\x00' * (4 - (len(data) % 4))) + data
+
+ result = 0
+
+ while len(data) > 0:
+ digit, = struct.unpack('>I', data[:4])
+ result = (result << 32) + digit
+ data = data[4:]
+
+ return result