3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
12 namespace Civi\Crypto
;
14 trait CryptoTestTrait
{
16 public static function getExampleKeys() {
18 ':b64:cGxlYXNlIHVzZSAzMiBieXRlcyBmb3IgYWVzLTI1NiE',
19 'aes-cbc:hkdf-sha256:abcd1234abcd1234',
20 'aes-ctr::abcd1234abcd1234',
21 'aes-cbc-hs::abcd1234abcd1234',
22 'jwt-hs256::abcd1234abcd1234',
23 'jwt-hs384:b64:8h5wNGnJbdVHpXms2RwcVx+jxCNdYEsYCdNlPpVgNLRMg9Q2xKYnxSfuihS6YCRi',
24 'jwt-hs256::fdsafdsafdsa',
29 * @param CryptoRegistry $registry
30 * @see \CRM_Utils_Hook::crypto()
32 public function registerExampleKeys($registry) {
33 $origCount = count($registry->getKeys());
35 $examples = self
::getExampleKeys();
36 $key = $registry->addSymmetricKey($registry->parseKey($examples[0]) +
[
37 'tags' => ['UNIT-TEST'],
41 $this->assertEquals(10, $key['weight']);
43 $key = $registry->addSymmetricKey($registry->parseKey($examples[1]) +
[
44 'tags' => ['UNIT-TEST'],
48 $this->assertEquals(-10, $key['weight']);
50 $key = $registry->addSymmetricKey($registry->parseKey($examples[2]) +
[
51 'tags' => ['UNIT-TEST'],
54 $this->assertEquals(0, $key['weight']);
56 $key = $registry->addSymmetricKey($registry->parseKey($examples[3]) +
[
57 'tags' => ['UNIT-TEST'],
60 $this->assertEquals(0, $key['weight']);
62 $key = $registry->addSymmetricKey($registry->parseKey($examples[4]) +
[
63 'tags' => ['SIGN-TEST'],
67 $this->assertEquals(1, $key['weight']);
69 $key = $registry->addSymmetricKey($registry->parseKey($examples[4]) +
[
70 'tags' => ['SIGN-TEST'],
73 $this->assertEquals(0, $key['weight']);
75 $key = $registry->addSymmetricKey($registry->parseKey($examples[4]) +
[
76 'tags' => ['SIGN-TEST-ALT'],
77 'id' => 'sign-key-alt',
79 $this->assertEquals(0, $key['weight']);
81 $this->assertEquals(7, count($examples));
82 $this->assertEquals(7 +
$origCount, count($registry->getKeys()));