code: def key_diff(key_bundle, key_defs):
      
  
      keys = key_bundle.get()
      diff = {}
  
      # My own sorted copy
      key_defs = order_key_defs(key_defs)[:]
      used = []
  
      for key in keys:
          match = False
          for kd in key_defs:
              if key.use not in kd['use']:
                  continue
  
              if key.kty != kd['type']:
                  continue
  
              if key.kty == 'EC':
                  # special test only for EC keys
                  if key.crv != kd['crv']:
                      continue
  
              try:
                  _kid = kd['kid']
              except KeyError:
                  pass
              else:
                  if key.kid != _kid:
                      continue
  
              match = True
              used.append(kd)
              key_defs.remove(kd)
              break
  
          if not match:
              try:
                  diff['del'].append(key)
              except KeyError:
                  diff['del'] = [key]
  
      if key_defs:
          _kb = build_key_bundle(key_defs)
          diff['add'] = _kb.keys()
  
      return diff
docs: Creates a difference dictionary with keys that should added and keys that
      should be deleted from a Key Bundle to get it updated to a state that
      mirrors What is in the key_defs specification.
  
      :param key_bundle: The original KeyBundle
      :param key_defs: A set of key definitions
      :return: A dictionary with possible keys 'add' and 'del'. The values
          for the keys are lists of :py:class:`cryptojwt.jwk.JWK` instances