ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Key.php
Go to the documentation of this file.
1 <?php
2 
3 namespace SAML2\Certificate;
4 
7 
12 class Key implements \ArrayAccess
13 {
14  // Possible key usages
15  const USAGE_SIGNING = 'signing';
16  const USAGE_ENCRYPTION = 'encryption';
17 
21  protected $keyData = array();
22 
26  public function __construct(array $keyData)
27  {
28  // forcing usage of offsetSet
29  foreach ($keyData as $property => $value) {
30  $this->offsetSet($property, $value);
31  }
32  }
33 
40  public function canBeUsedFor($usage)
41  {
42  if (!in_array($usage, static::getValidKeyUsages())) {
43  throw new InvalidKeyUsageException($usage);
44  }
45 
46  return isset($this->keyData[$usage]) && $this->keyData[$usage];
47  }
48 
53  public static function getValidKeyUsages()
54  {
55  return array(
56  self::USAGE_ENCRYPTION,
57  self::USAGE_SIGNING
58  );
59  }
60 
61  public function offsetExists($offset)
62  {
63  return array_key_exists($offset, $this->keyData);
64  }
65 
66  public function offsetGet($offset)
67  {
68  $this->assertIsString($offset);
69 
70  return $this->keyData[$offset];
71  }
72 
73  public function offsetSet($offset, $value)
74  {
75  $this->assertIsString($offset);
76 
77  $this->keyData[$offset] = $value;
78  }
79 
80  public function offsetUnset($offset)
81  {
82  $this->assertIsString($offset);
83 
84  unset($this->keyData[$offset]);
85  }
86 
93  protected function assertIsString($test)
94  {
95  if (!is_string($test)) {
97  }
98  }
99 }
const USAGE_ENCRYPTION
Definition: Key.php:16
Named exception for when a non-existent key-usage is given.
assertIsString($test)
Asserts that the parameter is of type string.
Definition: Key.php:93
offsetGet($offset)
Definition: Key.php:66
offsetExists($offset)
Definition: Key.php:61
Simple DTO wrapper for (X509) keys.
Definition: Key.php:12
canBeUsedFor($usage)
Whether or not the key is configured to be used for usage given.
Definition: Key.php:40
offsetUnset($offset)
Definition: Key.php:80
static getValidKeyUsages()
Returns the list of valid key usage options.
Definition: Key.php:53
Create styles array
The data for the language used.
__construct(array $keyData)
Definition: Key.php:26
const USAGE_SIGNING
Definition: Key.php:15
offsetSet($offset, $value)
Definition: Key.php:73
$test
Definition: Utf8Test.php:84