Class KeyUtils

  • All Implemented Interfaces:

    
    public final class KeyUtils
    
                        

    Helper functions for key look up in a set of keys. These functions also work when the key to look up in the set of keys is CompositeKey.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      static boolean isKeyInSet(@NotNull() PublicKey key, @NotNull() Set<PublicKey> otherKeys) Checks whether key has any intersection with the keys in otherKeys, recursing into key (the first argument) if it is a composite key.
      static boolean isKeyFulfilledBy(@NotNull() PublicKey key, @NotNull() Set<PublicKey> otherKeys) Return true if a set of keys fulfil the requirements of a specific key.
      static boolean isKeyFulfilledBy(@NotNull() PublicKey key, @NotNull() PublicKey otherKey) Return true if one key fulfills the requirements of another key.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • isKeyInSet

         static boolean isKeyInSet(@NotNull() PublicKey key, @NotNull() Set<PublicKey> otherKeys)

        Checks whether key has any intersection with the keys in otherKeys, recursing into key (the first argument) if it is a composite key. Does not match any composite keys in otherKeys.

        For simple non-compound public keys, this operation simply checks if the first argument occurs in the second argument. If key is a compound key, the outcome is whether any of its leaf keys are in otherKeys. PublicKey. This function checks against compound key tree leaves, which by definition are not CompositeKey. That is why if any of the otherKeys is a CompositeKey, this function will not find a match, though composite keys in the otherKeys set is not regarded as an error; they are silently ignored. The notion of a key being in a set is about equality, which is not the same as whether one key is fulfilled by another key. For example, a CompositeKey C could be defined to have threshold 2 and:
        • Public key X with weight 1
        • Public key Y with weight 1
        • Public key Z with weight 2
        Then we would find that isKeyInSet(C, X) is true, but X would not fulfill C since C is fulfilled by X and Y together but not X on its. However, isKeyInSet(C, Z) is true, and Z fulfills C by itself.
        Parameters:
        key - The key being looked for.
        otherKeys - The keys searched for the key.
      • isKeyFulfilledBy

         static boolean isKeyFulfilledBy(@NotNull() PublicKey key, @NotNull() Set<PublicKey> otherKeys)

        Return true if a set of keys fulfil the requirements of a specific key.

        Fulfilment of a CompositeKey as firstKey key is checked by delegating to the isFulfilledBy method of that compound key. It is a question of whether all the keys which match the compound keys in total have enough weight to reach the threshold of the primary key. In contrast, if this is called with firstKey being a simple public key, the test is whether firstKey is equal to any of the keys in otherKeys. Since a simple public key is never considered equal to a CompositeKey we know if firstKey is not composite, then it will not be considered fulfilled by any CompositeKey in otherKeys. Such cases are not considered errors, so we silently ignore CompositeKeys in otherKeys. If you know you have a CompositeKey in your hand, it would be simpler to call its isFulfilledBy() method directly. This function is intended as a utility for when you have some kind of public key, and which to check fulfilment against a set of keys, without having to handle simple and composite keys separately (that is, this is polymorphic).
        Parameters:
        key - The key to be checked whether it is being fulfilled by otherKeys.
        otherKeys - The keys against which the key is being checked for fulfilment.
      • isKeyFulfilledBy

         static boolean isKeyFulfilledBy(@NotNull() PublicKey key, @NotNull() PublicKey otherKey)

        Return true if one key fulfills the requirements of another key. See the previous variant; this overload is the same as calling as the variant that takes an iterable set of other keys with otherKey

        
             as a single element iterable.  
             

        
             Since we do not define composite keys as acceptable on the second argument of this function, this relation 
             is not reflexive, not symmetric and not transitive.

        Parameters:
        key - The key to be checked whether it is being fulfilled by otherKey.
        otherKey - The key against which the key is being checked for fulfilment.