File tree Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -37,14 +37,14 @@ The steps:
37
37
Verifying a signature
38
38
---------------------
39
39
40
- Verifying a signature works like this::
40
+ Verifying a signature works like this (_jws comes from the first signing example) ::
41
41
42
42
>>> from cryptojwt.jwk.hmac import SYMKey
43
43
>>> from cryptojwt.jws.jws import JWS
44
44
45
45
>>> key = SYMKey(key=b'My hollow echo chamber', alg="HS512")
46
46
>>> _verifier = JWS(alg="HS512")
47
- >>> _msg = _verifier.verify_compact([key])
47
+ >>> _msg = _verifier.verify_compact(_jws, [key])
48
48
>>> print(_msg)
49
49
"Please take a moment to register today"
50
50
@@ -56,5 +56,16 @@ The steps:
56
56
should give that information to the verifier as shown here. If you don't know you can leave it out.
57
57
3. Verify, using the compact or JSON method.
58
58
59
+ Or slightly different::
60
+
61
+ >>> from cryptojwt.jws.jws import factory
62
+ >>> from cryptojwt.jwk.hmac import SYMKey
63
+
64
+ >>> key = SYMKey(key=b'My hollow echo chamber', alg="HS512")
65
+ >>> _verifier = factory(_jwt)
66
+ >>> print(_verifier.verify_compact(_jwt, [key]))
67
+
68
+
69
+
59
70
60
71
.. _RFC7515 : https://tools.ietf.org/html/rfc7515
Original file line number Diff line number Diff line change @@ -392,6 +392,12 @@ def alg2keytype(self, alg):
392
392
def set_header_claim (self , key , value ):
393
393
self ._header [key ] = value
394
394
395
+ def verify_alg (self , alg ):
396
+ if alg == self .jwt .headers ['alg' ]:
397
+ return True
398
+ else :
399
+ return False
400
+
395
401
396
402
def factory (token ):
397
403
_jw = JWS ()
Original file line number Diff line number Diff line change @@ -451,6 +451,7 @@ def test_signer_ps512():
451
451
_rj = factory (_jwt )
452
452
info = _rj .verify_compact (_jwt , vkeys )
453
453
assert info == payload
454
+ assert _rj .verify_alg ('PS512' )
454
455
455
456
456
457
def test_no_alg_and_alg_none_same ():
You can’t perform that action at this time.
0 commit comments