summaryrefslogtreecommitdiffstats
path: root/jwcrypto
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2015-03-04 11:18:24 -0500
committerSimo Sorce <simo@redhat.com>2015-03-04 21:29:59 -0500
commiteb1fb55ac331a2f7d73acd7f3034617cdcdff41e (patch)
tree79183d3506d1fd31118e707d46c38a0dcb1024ba /jwcrypto
downloadjwcrypto-eb1fb55ac331a2f7d73acd7f3034617cdcdff41e.tar.gz
jwcrypto-eb1fb55ac331a2f7d73acd7f3034617cdcdff41e.tar.xz
jwcrypto-eb1fb55ac331a2f7d73acd7f3034617cdcdff41e.zip
Initial commit
Project for the implementation of the JOSE WG protocols Add some commong functions. Signed-off-by: Simo Sorce <simo@redhat.com>
Diffstat (limited to 'jwcrypto')
-rw-r--r--jwcrypto/__init__.py0
-rw-r--r--jwcrypto/common.py22
2 files changed, 22 insertions, 0 deletions
diff --git a/jwcrypto/__init__.py b/jwcrypto/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/jwcrypto/__init__.py
diff --git a/jwcrypto/common.py b/jwcrypto/common.py
new file mode 100644
index 0000000..e348b44
--- /dev/null
+++ b/jwcrypto/common.py
@@ -0,0 +1,22 @@
+# Copyright (C) 2015 JWCrypto Project Contributors - see LICENSE file
+
+from base64 import urlsafe_b64encode, urlsafe_b64decode
+
+
+# Padding stripping versions as described in
+# draft-ietf-jose-json-web-signature-41 appendix C
+
+
+def base64url_encode(payload):
+ return urlsafe_b64encode(payload).rstrip('=')
+
+
+def base64url_decode(payload):
+ l = len(payload) % 4
+ if l == 2:
+ payload += '=='
+ elif l == 3:
+ payload += '='
+ elif l != 0:
+ raise ValueError('Invalid base64 string')
+ return urlsafe_b64decode(payload)