From 8d54915f6e38f4e786f0a3839ba7d48fb8306000 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 21 Dec 2020 00:15:27 -0800 Subject: [PATCH] (dev/core#2258) CryptoRegistry - Add findKeysByTag() --- Civi/Crypto/CryptoRegistry.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Civi/Crypto/CryptoRegistry.php b/Civi/Crypto/CryptoRegistry.php index 21e1d103cf..c979a257d6 100644 --- a/Civi/Crypto/CryptoRegistry.php +++ b/Civi/Crypto/CryptoRegistry.php @@ -233,6 +233,24 @@ class CryptoRegistry { 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 -- 2.25.1