Skip to content

Commit

Permalink
(dev/core#2258) CryptoRegistry - Add findKeysByTag()
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Dec 21, 2020
1 parent a4c9a24 commit 4d8230c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Civi/Crypto/CryptoRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,24 @@ public function findKey($keyIds) {
throw new CryptoException("Failed to find key by ID or tag (" . implode(' ', $keyIds) . ")");
}

/**
* Find all the keys that apply to a tag.
*
* @param string $keyTag
*
* @return array
* List of keys, indexed by id, ordered by weight.
*/
public function findKeysByTag($keyTag) {
$keys = array_filter($this->keys, function ($key) use ($keyTag) {
return in_array($keyTag, $key['tags'] ?? []);
});
uasort($keys, function($a, $b) {
return ($a['weight'] ?? 0) - ($b['weight'] ?? 0);
});
return $keys;
}

/**
* @param string $name
* @return \Civi\Crypto\CipherSuiteInterface
Expand Down

0 comments on commit 4d8230c

Please sign in to comment.