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.
-
-
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 inotherKeys
, recursing intokey
(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. -
-
Method Detail
-
isKeyInSet
static boolean isKeyInSet(@NotNull() PublicKey key, @NotNull() Set<PublicKey> otherKeys)
Checks whether
For simple non-compound public keys, this operation simply checks if the first argument occurs in the second argument. Ifkey
has any intersection with the keys inotherKeys
, recursing intokey
(the first argument) if it is a composite key. Does not match any composite keys inotherKeys
.key
is a compound key, the outcome is whether any of its leaf keys are inotherKeys
. PublicKey. This function checks against compound key tree leaves, which by definition are not CompositeKey. That is why if any of theotherKeys
is a CompositeKey, this function will not find a match, though composite keys in theotherKeys
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
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 thekey
.
-
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 asfirstKey
key is checked by delegating to theisFulfilledBy
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 withfirstKey
being a simple public key, the test is whetherfirstKey
is equal to any of the keys inotherKeys
. Since a simple public key is never considered equal to a CompositeKey we know iffirstKey
is not composite, then it will not be considered fulfilled by any CompositeKey inotherKeys
. Such cases are not considered errors, so we silently ignore CompositeKeys inotherKeys
. If you know you have a CompositeKey in your hand, it would be simpler to call itsisFulfilledBy()
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 byotherKeys
.otherKeys
- The keys against which thekey
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 byotherKey
.otherKey
- The key against which thekey
is being checked for fulfilment.
-
-
-
-