1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\XML\xenc; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\XMLSchema\Type\AnyURIValue; |
9
|
|
|
use SimpleSAML\XMLSchema\Type\IDValue; |
10
|
|
|
use SimpleSAML\XMLSchema\Type\StringValue; |
11
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\KeyInfo; |
12
|
|
|
|
13
|
|
|
use function strval; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Abstract class representing encrypted data. |
17
|
|
|
* |
18
|
|
|
* Note: <xenc:EncryptionProperties> elements are not supported. |
19
|
|
|
* |
20
|
|
|
* @package simplesamlphp/xml-security |
21
|
|
|
*/ |
22
|
|
|
abstract class AbstractEncryptedType extends AbstractXencElement |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* EncryptedData constructor. |
26
|
|
|
* |
27
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\xenc\CipherData $cipherData The CipherData object of this EncryptedData. |
28
|
|
|
* @param \SimpleSAML\XMLSchema\Type\IDValue|null $id The Id attribute of this object. Optional. |
29
|
|
|
* @param \SimpleSAML\XMLSchema\Type\AnyURIValue|null $type The Type attribute of this object. Optional. |
30
|
|
|
* @param \SimpleSAML\XMLSchema\Type\StringValue|null $mimeType |
31
|
|
|
* The MimeType attribute of this object. Optional. |
32
|
|
|
* @param \SimpleSAML\XMLSchema\Type\AnyURIValue|null $encoding |
33
|
|
|
* The Encoding attribute of this object. Optional. |
34
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\xenc\EncryptionMethod|null $encryptionMethod |
35
|
|
|
* The EncryptionMethod object of this EncryptedData. Optional. |
36
|
|
|
* @param \SimpleSAML\XMLSecurity\XML\ds\KeyInfo|null $keyInfo The KeyInfo object of this EncryptedData. Optional. |
37
|
|
|
*/ |
38
|
|
|
public function __construct( |
39
|
|
|
protected CipherData $cipherData, |
40
|
|
|
protected ?IDValue $id = null, |
41
|
|
|
protected ?AnyURIValue $type = null, |
42
|
|
|
protected ?StringValue $mimeType = null, |
43
|
|
|
protected ?AnyURIValue $encoding = null, |
44
|
|
|
protected ?EncryptionMethod $encryptionMethod = null, |
45
|
|
|
protected ?KeyInfo $keyInfo = null, |
46
|
|
|
) { |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get the CipherData object. |
52
|
|
|
* |
53
|
|
|
* @return \SimpleSAML\XMLSecurity\XML\xenc\CipherData |
54
|
|
|
*/ |
55
|
|
|
public function getCipherData(): CipherData |
56
|
|
|
{ |
57
|
|
|
return $this->cipherData; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Get the value of the Encoding attribute. |
63
|
|
|
* |
64
|
|
|
* @return \SimpleSAML\XMLSchema\Type\AnyURIValue|null |
65
|
|
|
*/ |
66
|
|
|
public function getEncoding(): ?AnyURIValue |
67
|
|
|
{ |
68
|
|
|
return $this->encoding; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Get the EncryptionMethod object. |
74
|
|
|
* |
75
|
|
|
* @return \SimpleSAML\XMLSecurity\XML\xenc\EncryptionMethod|null |
76
|
|
|
*/ |
77
|
|
|
public function getEncryptionMethod(): ?EncryptionMethod |
78
|
|
|
{ |
79
|
|
|
return $this->encryptionMethod; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get the value of the Id attribute. |
85
|
|
|
* |
86
|
|
|
* @return \SimpleSAML\XMLSchema\Type\IDValue |
87
|
|
|
*/ |
88
|
|
|
public function getID(): ?IDValue |
89
|
|
|
{ |
90
|
|
|
return $this->id; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Get the KeyInfo object. |
96
|
|
|
* |
97
|
|
|
* @return \SimpleSAML\XMLSecurity\XML\ds\KeyInfo|null |
98
|
|
|
*/ |
99
|
|
|
public function getKeyInfo(): ?KeyInfo |
100
|
|
|
{ |
101
|
|
|
return $this->keyInfo; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Get the value of the MimeType attribute. |
107
|
|
|
* |
108
|
|
|
* @return \SimpleSAML\XMLSchema\Type\StringValue |
109
|
|
|
*/ |
110
|
|
|
public function getMimeType(): ?StringValue |
111
|
|
|
{ |
112
|
|
|
return $this->mimeType; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Get the value of the Type attribute. |
118
|
|
|
* |
119
|
|
|
* @return \SimpleSAML\XMLSchema\Type\AnyURIValue|null |
120
|
|
|
*/ |
121
|
|
|
public function getType(): ?AnyURIValue |
122
|
|
|
{ |
123
|
|
|
return $this->type; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @inheritDoc |
129
|
|
|
*/ |
130
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
131
|
|
|
{ |
132
|
|
|
$e = $this->instantiateParentElement($parent); |
133
|
|
|
|
134
|
|
|
$id = $this->getId(); |
135
|
|
|
if ($id !== null) { |
136
|
|
|
$e->setAttribute('Id', strval($id)); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
$type = $this->getType(); |
140
|
|
|
if ($type !== null) { |
141
|
|
|
$e->setAttribute('Type', strval($type)); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
$mimeType = $this->getMimeType(); |
145
|
|
|
if ($mimeType !== null) { |
146
|
|
|
$e->setAttribute('MimeType', strval($mimeType)); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
$encoding = $this->getEncoding(); |
150
|
|
|
if ($encoding !== null) { |
151
|
|
|
$e->setAttribute('Encoding', strval($encoding)); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
$this->getEncryptionMethod()?->toXML($e); |
155
|
|
|
$this->getKeyInfo()?->toXML($e); |
156
|
|
|
$this->getCipherData()->toXML($e); |
157
|
|
|
|
158
|
|
|
return $e; |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|