ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
KeyRotationObjective.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\FileDelivery\Setup;
22 
26 
31 {
32  public const KEY_LENGTH = 32;
36  private const NUMBER_OF_KEYS = 5;
37  public function getArtifactName(): string
38  {
39  return "key_rotation";
40  }
41 
42 
43  public function build(): Artifact
44  {
45  $current_keys = null;
46  if (is_readable(self::PATH())) {
48  $current_keys = require self::PATH();
49  }
50 
51  $new_keys = [];
52 
53  if (is_array($current_keys)) {
54  // drop the first key
55  $current_keys = array_slice($current_keys, 1);
56  $new_keys = $current_keys;
57  }
58  // $push a new key to the array at first position
59  while (count($new_keys) < self::NUMBER_OF_KEYS) {
60  $new_keys[] = $this->generateRandomString(self::KEY_LENGTH);
61  }
62  // keep only the first 5 keys
63  $new_keys = array_slice($new_keys, 0, self::NUMBER_OF_KEYS);
64 
65  return new ArrayArtifact($new_keys);
66  }
67 
68  private function generateRandomString(int $length): string
69  {
70  $return = '';
71  for ($i = 0; $i < $length; $i++) {
72  $return .= chr(random_int(33, 125));
73  }
74  return $return;
75  }
76 }
build()
Build the artifact based.
This is an objective to build some artifact.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
An array as an artifact.
An artifact is some file that is build on demand per installation and is not shipped with the ILIAS s...
Definition: Artifact.php:27