ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
KeyRotationObjective.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25
30{
31 public const KEY_LENGTH = 32;
32 private const int NUMBER_OF_KEYS = 5;
33
34 public function getArtifactName(): string
35 {
36 return "key_rotation";
37 }
38
39 public function build(): Artifact
40 {
41 $current_keys = null;
42 if (is_readable(self::PATH())) {
44 $current_keys = require self::PATH();
45 }
46
47 $new_keys = [];
48
49 if (is_array($current_keys)) {
50 // drop the first key
51 $current_keys = array_slice($current_keys, 1);
52 $new_keys = $current_keys;
53 }
54 // $push a new key to the array at first position
55 while (count($new_keys) < self::NUMBER_OF_KEYS) {
56 $new_keys[] = $this->generateRandomString(self::KEY_LENGTH);
57 }
58 // keep only the first 5 keys
59 $new_keys = array_slice($new_keys, 0, self::NUMBER_OF_KEYS);
60
61 return new ArrayArtifact($new_keys);
62 }
63
64 private function generateRandomString(int $length): string
65 {
66 $return = '';
67 for ($i = 0; $i < $length; $i++) {
68 $return .= chr(random_int(33, 125));
69 }
70 return $return;
71 }
72}
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:28