1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SAML2\XML\xenc; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SAML2\Utils; |
9
|
|
|
use Webmozart\Assert\Assert; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class representing <xenc:CipherData>. |
13
|
|
|
* |
14
|
|
|
* @package simplesamlphp/saml2 |
15
|
|
|
*/ |
16
|
|
|
class CipherData extends AbstractXencElement |
17
|
|
|
{ |
18
|
|
|
/** @var string */ |
19
|
|
|
protected $cipherValue; |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* CipherData constructor. |
24
|
|
|
* |
25
|
|
|
* @param string $cipherValue |
26
|
|
|
*/ |
27
|
|
|
public function __construct(string $cipherValue) |
28
|
|
|
{ |
29
|
|
|
$this->setCipherValue($cipherValue); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Get the string value of the <xenc:CipherValue> element inside this CipherData object. |
35
|
|
|
* |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
|
|
public function getCipherValue(): string |
39
|
|
|
{ |
40
|
|
|
return $this->cipherValue; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param string $cipherValue |
46
|
|
|
*/ |
47
|
|
|
protected function setCipherValue(string $cipherValue) |
48
|
|
|
{ |
49
|
|
|
Assert::regex($cipherValue, '/[a-zA-Z0-9_\-=\+\/]/', 'Invalid data in <xenc:CipherValue>.'); |
50
|
|
|
$this->cipherValue = $cipherValue; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @inheritDoc |
56
|
|
|
* @throws \Exception |
57
|
|
|
*/ |
58
|
|
|
public static function fromXML(DOMElement $xml): object |
59
|
|
|
{ |
60
|
|
|
Assert::same($xml->localName, 'CipherData'); |
61
|
|
|
Assert::same($xml->namespaceURI, CipherData::NS); |
62
|
|
|
|
63
|
|
|
$cv = Utils::xpQuery($xml, './xenc:CipherValue'); |
64
|
|
|
Assert::notEmpty($cv, 'Missing CipherValue element in <xenc:CipherData>'); |
65
|
|
|
Assert::count($cv, 1, 'More than one CipherValue element in <xenc:CipherData'); |
66
|
|
|
|
67
|
|
|
return new self($cv[0]->textContent); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @inheritDoc |
73
|
|
|
*/ |
74
|
|
|
public function toXML(DOMElement $parent = null): DOMElement |
75
|
|
|
{ |
76
|
|
|
$e = $this->instantiateParentElement($parent); |
77
|
|
|
|
78
|
|
|
$cv = $e->ownerDocument->createElementNS($this::NS, $this::NS_PREFIX . ':CipherValue'); |
79
|
|
|
$cv->textContent = $this->cipherValue; |
80
|
|
|
$e->appendChild($cv); |
81
|
|
|
|
82
|
|
|
return $e; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|