@@ -387,17 +387,53 @@ def _is_compact_jws(self, jws):
387
387
return True
388
388
389
389
def alg2keytype (self , alg ):
390
+ """
391
+ Translate a signing algorithm into a specific key type.
392
+
393
+ :param alg: The signing algorithm
394
+ :return: A key type or None if there is no key type matching the
395
+ algorithm
396
+ """
390
397
return alg2keytype (alg )
391
398
392
399
def set_header_claim (self , key , value ):
400
+ """
401
+ Set a specific claim in the header to a specific value.
402
+
403
+ :param key: The name of the claim
404
+ :param value: The value of the claim
405
+ """
393
406
self ._header [key ] = value
394
407
395
408
def verify_alg (self , alg ):
409
+ """
410
+ Specifically check that the 'alg' claim has a specific value
411
+
412
+ :param alg: The expected alg value
413
+ :raises: KeyError if the 'alg' is not present in the header
414
+ :return: True if the alg value in the header is the same as the one
415
+ given.
416
+ """
396
417
if alg == self .jwt .headers ['alg' ]:
397
418
return True
398
419
else :
399
420
return False
400
421
422
+ def verify_header (self , key , val ):
423
+ """
424
+ Check that a particular header claim is present as a has specific value
425
+
426
+ :param key: The claim
427
+ :param val: The value of the claim
428
+ :raises: KeyError if the claim is not present in the header
429
+ :return: True if the claim exists in the header and has the prescribed
430
+ value
431
+ """
432
+ if val == self .jwt .headers [key ]:
433
+ return True
434
+ else :
435
+ return False
436
+
401
437
402
438
def factory (token , ** kwargs ):
403
439
_jw = JWS (** kwargs )
0 commit comments