Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Custom algoritms work!

  • Loading branch information...
commit 0ca910a222dbcc7da7a3acb58460b31f3c8266ac 1 parent b7bb574
Brian J Brennan authored
1  jws/__init__.py
@@ -3,7 +3,6 @@
3 3
 # local 
4 4
 import algos
5 5
 import header
6  
-import router
7 6
 
8 7
 class MissingKey(Exception): pass
9 8
 class MissingSigner(Exception): pass
21  jws/tests.py
@@ -48,14 +48,21 @@ def sign(self): self.data['key'] = self.value
48 48
         self.assertEqual(data['key'], 'somethingelse')
49 49
         
50 50
     def test_custom_algorithm(self):
51  
-        class F7U12(jws.AlgorithmBase):
  51
+        class F7U12(jws.algos.AlgorithmBase):
52 52
             def __init__(self): pass
53  
-            def sign(msg, key):
54  
-                return 'u mad?'
55  
-            def verify(msg, sig, key):
56  
-                if sig == 'u mad?': return '<trollface>'
57  
-                raise jws.SignatureError('Y U NO GIVE GOOD SIGNATURE')
58  
-        print F7U12
  53
+            def sign(self, msg, key):
  54
+                return 'u mad?' + key
  55
+            def verify(self, msg, sig, key):
  56
+                if sig == 'u mad?' + key: return '<trollface>'
  57
+                raise jws.algos.SignatureError('Y U NO GIVE GOOD SIGNATURE')
  58
+        jws.algos.CUSTOM = [ ('F7U12',  F7U12) ]
  59
+        header = {'alg': 'F7U12'}
  60
+        payload = {'some': 'claim'}
  61
+        
  62
+        sig = jws.sign(header, payload, 'wutlol')
  63
+        self.assertEqual(jws.verify(header,payload,sig, 'wutlol'), '<trollface>')
  64
+        self.assertRaises(jws.algos.SignatureError, jws.verify, header, payload, sig, 'raaaaage')
  65
+        
59 66
 
60 67
 class TestJWS_ecdsa(unittest.TestCase):
61 68
     sk256 = ecdsa.SigningKey.generate(ecdsa.NIST256p)

0 notes on commit 0ca910a

Please sign in to comment.
Something went wrong with that request. Please try again.