@@ -694,6 +694,13 @@ def build_key_bundle(key_conf, kid_template=""):
694
694
695
695
696
696
def _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
+ """
697
704
if kd1 == kd2 :
698
705
return 0
699
706
elif kd1 < kd2 :
@@ -703,6 +710,12 @@ def _cmp(kd1, kd2):
703
710
704
711
705
712
def 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
+ """
706
719
_l = _cmp (kd1 ['type' ], kd2 ['type' ])
707
720
if _l :
708
721
return _l
@@ -742,9 +755,12 @@ def sort_func(kd1, kd2):
742
755
743
756
def order_key_defs (key_def ):
744
757
"""
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.
745
761
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
748
764
"""
749
765
_int = []
750
766
# First make sure all defs only reference one usage
@@ -762,15 +778,16 @@ def order_key_defs(key_def):
762
778
return _int
763
779
764
780
765
- def key_diff (key_bundle , key_defs , owner = '' ):
781
+ def key_diff (key_bundle , key_defs ):
766
782
"""
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
774
791
"""
775
792
776
793
keys = key_bundle .get ()
@@ -821,6 +838,15 @@ def key_diff(key_bundle, key_defs, owner=''):
821
838
822
839
823
840
def 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
+ """
824
850
try :
825
851
_add = diff ['add' ]
826
852
except KeyError :
@@ -839,11 +865,18 @@ def update_key_bundle(key_bundle, diff):
839
865
840
866
841
867
def 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
+ """
842
877
key_spec = []
843
878
for key in kb .get ():
844
879
_spec = {'type' : key .kty , 'use' :[key .use ]}
845
- if key .kid :
846
- _spec ['kid' ] = key .kid
847
880
if key .kty == 'EC' :
848
881
_spec ['crv' ] = key .crv
849
882
0 commit comments