File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,14 +37,14 @@ The steps:
3737Verifying a signature
3838---------------------
3939
40- Verifying a signature works like this::
40+ Verifying a signature works like this (_jws comes from the first signing example) ::
4141
4242 >>> from cryptojwt.jwk.hmac import SYMKey
4343 >>> from cryptojwt.jws.jws import JWS
4444
4545 >>> key = SYMKey(key=b'My hollow echo chamber', alg="HS512")
4646 >>> _verifier = JWS(alg="HS512")
47- >>> _msg = _verifier.verify_compact([key])
47+ >>> _msg = _verifier.verify_compact(_jws, [key])
4848 >>> print(_msg)
4949 "Please take a moment to register today"
5050
@@ -56,5 +56,16 @@ The steps:
5656 should give that information to the verifier as shown here. If you don't know you can leave it out.
5757 3. Verify, using the compact or JSON method.
5858
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+
5970
6071.. _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):
392392 def set_header_claim (self , key , value ):
393393 self ._header [key ] = value
394394
395+ def verify_alg (self , alg ):
396+ if alg == self .jwt .headers ['alg' ]:
397+ return True
398+ else :
399+ return False
400+
395401
396402def factory (token ):
397403 _jw = JWS ()
Original file line number Diff line number Diff line change @@ -451,6 +451,7 @@ def test_signer_ps512():
451451 _rj = factory (_jwt )
452452 info = _rj .verify_compact (_jwt , vkeys )
453453 assert info == payload
454+ assert _rj .verify_alg ('PS512' )
454455
455456
456457def test_no_alg_and_alg_none_same ():
You can’t perform that action at this time.
0 commit comments