From d463c543e5b25e8782a616042082d21e0fd2ec6a Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 21 Dec 2020 00:10:24 -0800 Subject: [PATCH] (dev/core#2258) CryptoRegistry - Allow multiple plaintext entries This allows the plaintext entries to do have different prioritizations among different keys. --- Civi/Crypto/CryptoRegistry.php | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/Civi/Crypto/CryptoRegistry.php b/Civi/Crypto/CryptoRegistry.php index 0cca04fe89..21e1d103cf 100644 --- a/Civi/Crypto/CryptoRegistry.php +++ b/Civi/Crypto/CryptoRegistry.php @@ -68,10 +68,13 @@ class CryptoRegistry { $registry->addPlainText(['tags' => ['CRED']]); if (defined('CIVICRM_CRED_KEYS')) { foreach (explode(' ', CIVICRM_CRED_KEYS) as $n => $keyExpr) { - $registry->addSymmetricKey($registry->parseKey($keyExpr) + [ - 'tags' => ['CRED'], - 'weight' => $n, - ]); + $key = ['tags' => ['CRED'], 'weight' => $n]; + if ($keyExpr === 'plain') { + $registry->addPlainText($key); + } + else { + $registry->addSymmetricKey($registry->parseKey($keyExpr) + $key); + } } } @@ -169,14 +172,15 @@ class CryptoRegistry { * @return array */ public function addPlainText($options) { - if (!isset($this->keys['plain'])) { - } - if (isset($options['tags'])) { - $this->keys['plain']['tags'] = array_merge( - $options['tags'] - ); - } - return $this->keys['plain']; + static $n = 0; + $defaults = [ + 'suite' => 'plain', + 'weight' => self::LAST_WEIGHT, + ]; + $options = array_merge($defaults, $options); + $options['id'] = 'plain' . ($n++); + $this->keys[$options['id']] = $options; + return $options; } /** -- 2.25.1