projects
/
civicrm-core.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #23190 from eileenmcnaughton/pradeep
[civicrm-core.git]
/
Civi
/
Crypto
/
CryptoToken.php
diff --git
a/Civi/Crypto/CryptoToken.php
b/Civi/Crypto/CryptoToken.php
index 9ee7375ac6950c9e0cf7e803ee246d24e5ef74cf..afe415d844f85b62315ef5cc5de36c775d5e9aa8 100644
(file)
--- a/
Civi/Crypto/CryptoToken.php
+++ b/
Civi/Crypto/CryptoToken.php
@@
-55,11
+55,19
@@
class CryptoToken {
*/
protected $delim;
*/
protected $delim;
+ /**
+ * @var \Civi\Crypto\CryptoRegistry|null
+ */
+ private $registry;
+
/**
* CryptoToken constructor.
/**
* CryptoToken constructor.
+ *
+ * @param CryptoRegistry $registry
*/
*/
- public function __construct() {
+ public function __construct(
$registry = NULL
) {
$this->delim = chr(2);
$this->delim = chr(2);
+ $this->registry = $registry;
}
/**
}
/**
@@
-69,7
+77,7
@@
class CryptoToken {
* @return bool
*/
public function isPlainText($plainText) {
* @return bool
*/
public function isPlainText($plainText) {
- return is_string($plainText) && ($plainText === '' || $plainText
{0}
!== $this->delim);
+ return is_string($plainText) && ($plainText === '' || $plainText
[0]
!== $this->delim);
}
/**
}
/**
@@
-85,7
+93,7
@@
class CryptoToken {
*/
public function encrypt($plainText, $keyIdOrTag) {
/** @var CryptoRegistry $registry */
*/
public function encrypt($plainText, $keyIdOrTag) {
/** @var CryptoRegistry $registry */
- $registry =
\Civi::service('crypto.registry'
);
+ $registry =
$this->getRegistry(
);
$key = $registry->findKey($keyIdOrTag);
if ($key['suite'] === 'plain') {
$key = $registry->findKey($keyIdOrTag);
if ($key['suite'] === 'plain') {
@@
-128,7
+136,7
@@
class CryptoToken {
}
/** @var CryptoRegistry $registry */
}
/** @var CryptoRegistry $registry */
- $registry =
\Civi::service('crypto.registry'
);
+ $registry =
$this->getRegistry(
);
$tokenData = $this->parse($token);
$tokenData = $this->parse($token);
@@
-156,7
+164,7
@@
class CryptoToken {
*/
public function rekey($oldToken, $keyTag) {
/** @var \Civi\Crypto\CryptoRegistry $registry */
*/
public function rekey($oldToken, $keyTag) {
/** @var \Civi\Crypto\CryptoRegistry $registry */
- $registry =
\Civi::service('crypto.registry'
);
+ $registry =
$this->getRegistry(
);
$sourceKeys = $registry->findKeysByTag($keyTag);
$targetKey = array_shift($sourceKeys);
$sourceKeys = $registry->findKeysByTag($keyTag);
$targetKey = array_shift($sourceKeys);
@@
-200,4
+208,14
@@
class CryptoToken {
return $tokenData;
}
return $tokenData;
}
+ /**
+ * @return CryptoRegistry
+ */
+ protected function getRegistry(): CryptoRegistry {
+ if ($this->registry === NULL) {
+ $this->registry = \Civi::service('crypto.registry');
+ }
+ return $this->registry;
+ }
+
}
}