(dev/core#2258) CryptoRegistry - Allow multiple plaintext entries
authorTim Otten <totten@civicrm.org>
Mon, 21 Dec 2020 08:10:24 +0000 (00:10 -0800)
committerTim Otten <totten@civicrm.org>
Mon, 21 Dec 2020 10:16:30 +0000 (02:16 -0800)
This allows the plaintext entries to do have different prioritizations among
different keys.

Civi/Crypto/CryptoRegistry.php

index 0cca04fe8912f14c341edfab2ca2fe33cf13b333..21e1d103cf2c15cbbce359d012fec737a97ad306 100644 (file)
@@ -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;
   }
 
   /**