@@ -694,6 +694,13 @@ def build_key_bundle(key_conf, kid_template=""):
694694
695695
696696def _cmp (kd1 , kd2 ):
697+ """
698+ Compare 2 keys
699+
700+ :param kd1: First key
701+ :param kd2: Second key
702+ :return: -1,0,1 depending on whether kd1 is le,eq or gt then kd2
703+ """
697704 if kd1 == kd2 :
698705 return 0
699706 elif kd1 < kd2 :
@@ -703,6 +710,12 @@ def _cmp(kd1, kd2):
703710
704711
705712def sort_func (kd1 , kd2 ):
713+ """
714+ Compares 2 key descriptions
715+ :param kd1: First key description
716+ :param kd2: Second key description
717+ :return: -1,0,1 depending on whether kd1 le,eq or gt then kd2
718+ """
706719 _l = _cmp (kd1 ['type' ], kd2 ['type' ])
707720 if _l :
708721 return _l
@@ -742,9 +755,12 @@ def sort_func(kd1, kd2):
742755
743756def order_key_defs (key_def ):
744757 """
758+ Sort a set of key definitions. A key definition that defines more then
759+ one usage type are splitted into as many definitions as the number of
760+ usage types specified. One key definition per usage type.
745761
746- :param key_def:
747- :return:
762+ :param key_def: A set of key definitions
763+ :return: The set of definitions as a sorted list
748764 """
749765 _int = []
750766 # First make sure all defs only reference one usage
@@ -762,15 +778,16 @@ def order_key_defs(key_def):
762778 return _int
763779
764780
765- def key_diff (key_bundle , key_defs , owner = '' ):
781+ def key_diff (key_bundle , key_defs ):
766782 """
767- Compares a KeyJar instance with a key specification and returns
768- what new keys should be created and added to the key_jar and which should be
769- removed from the key_jar.
770-
771- :param key_jar:
772- :param key_defs:
773- :return:
783+ Creates a difference dictionary with keys that should added and keys that
784+ should be deleted from a Key Bundle to get it updated to a state that
785+ mirrors What is in the key_defs specification.
786+
787+ :param key_bundle: The original KeyBundle
788+ :param key_defs: A set of key definitions
789+ :return: A dictionary with possible keys 'add' and 'del'. The values
790+ for the keys are lists of :py:class:`cryptojwt.jwk.JWK` instances
774791 """
775792
776793 keys = key_bundle .get ()
@@ -821,6 +838,15 @@ def key_diff(key_bundle, key_defs, owner=''):
821838
822839
823840def update_key_bundle (key_bundle , diff ):
841+ """
842+ Apply a diff specification to a KeyBundle.
843+ The keys that are to be added are added.
844+ The keys that should be deleted are marked as inactive.
845+
846+ :param key_bundle: The original KeyBundle
847+ :param diff: The difference specification
848+ :return: An updated key_bundle
849+ """
824850 try :
825851 _add = diff ['add' ]
826852 except KeyError :
@@ -839,11 +865,18 @@ def update_key_bundle(key_bundle, diff):
839865
840866
841867def key_rollover (kb ):
868+ """
869+ A nifty function that lets you do a key rollover that encompasses creating
870+ a completely new set of keys. One new per every old one. With the same
871+ specifications as the old one.
872+ All the old ones are marked as inactive.
873+
874+ :param kb:
875+ :return:
876+ """
842877 key_spec = []
843878 for key in kb .get ():
844879 _spec = {'type' : key .kty , 'use' :[key .use ]}
845- if key .kid :
846- _spec ['kid' ] = key .kid
847880 if key .kty == 'EC' :
848881 _spec ['crv' ] = key .crv
849882
0 commit comments