Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

update readme

  • Loading branch information...
commit ec9cfe4ebd9b16cffbf3ec91910d611d0c3a187d 1 parent 8f818a2
Brian J Brennan authored June 02, 2011
13  README.md
Source Rendered
@@ -16,7 +16,7 @@ The JWS spec reserves several algorithms for cryptographic signing. Out of the 9
16 16
 * HS256 – HMAC using SHA-256 hash algorithm
17 17
 * HS384 – HMAC using SHA-384 hash algorithm
18 18
 * HS512 – HMAC using SHA-512 hash algorithm
19  
-* RS256 – RSA using SHA-256 hash algorithm
  19
+* RS256 – RSA using SHA-256 hash algorithm <strong>*</strong>
20 20
 * ES256 – ECDSA using P-256 curve and SHA-256 hash algorithm
21 21
 * ES384 – ECDSA using P-384 curve and SHA-384 hash algorithm
22 22
 * ES512 – ECDSA using P-521 curve and SHA-512 hash algorithm
@@ -25,6 +25,11 @@ There is also a mechanism for extending functionality by adding your own
25 25
 algorithms without cracking open the whole codebase. See the advanced usage
26 26
 section for an example.
27 27
 
  28
+<strong>NOTE:</strong> you must use the version of pycrypto in vendor/pycrypto
  29
+to get RSA256 support. However if you don't ever plan on using RSA, you don't
  30
+have to worry about it – all crypto libraries are lazily loaded so you won't
  31
+even notice it's not there.
  32
+
28 33
 Usage
29 34
 -----
30 35
 Let's check out some examples.    
@@ -69,7 +74,11 @@ Make this file
69 74
                 raise SignatureError('nope')
70 75
             return True
71 76
 
72  
-    jws.algos.CUSTOM = [
  77
+    jws.algos.CUSTOM += [
  78
+        
  79
+        # a regular expression with two named matching groups. (x and y)
  80
+        # named groups will be sent to the class constructor
  81
+        (r'^F(?P<x>\d)U(?P<y>\d{2})$',  FXUY),
73 82
         (r'^F(?P<x>\d)U(?P<y>\d{2})$',  FXUY),
74 83
     ]
75 84
 
34  examples/ragecrypto.py
... ...
@@ -0,0 +1,34 @@
  1
+import jws
  2
+from jws.algos import AlgorithmBase, SignatureError
  3
+
  4
+class FXUY(AlgorithmBase):
  5
+    # initializer gets variables from algo router
  6
+    # named groups in the regexp get sent here.
  7
+    def __init__(self, fval, uval):
  8
+        self.x = len(fval)
  9
+        self.y = len(uval)
  10
+
  11
+    # straightforward, just return the signature
  12
+    def sign(self, msg, key):
  13
+        return 'srs' * self.x + key + 'bzns' * self.y + msg
  14
+ 
  15
+    # verify should only return if the signature is valid.
  16
+    # otherwise raise a SignatureError
  17
+    def verify(self, msg, sig, key):
  18
+        if sig != self.sign(msg, key):
  19
+            raise SignatureError('nope')
  20
+        return True
  21
+
  22
+# algos.CUSTOM is a list that holds custom algorithms.
  23
+# the format is [(routing_regex, algorithm_class)...]
  24
+#
  25
+# values from the 'alg' key in headers are run through each algorithm
  26
+# routing_regex, stopping on the first one that matches. algos in the CUSTOM
  27
+# list take precedence over the defaults -- note that this means you can add
  28
+# override any default algorithms by defining a custom algorithm with a
  29
+# routing_regex that matches one of the defaults.
  30
+jws.algos.CUSTOM = [
  31
+    # a regular expression with two named matching groups.
  32
+    # named groups will be sent to the class constructor
  33
+    (r'^(?P<fval>f+)(?P<uval>u+)$',  FXUY),
  34
+]

0 notes on commit ec9cfe4

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