1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\XML\dsig11; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\XML\Chunk; |
10
|
|
|
use SimpleSAML\XML\ExtendableElementTrait; |
11
|
|
|
use SimpleSAML\XML\SerializableElementInterface; |
12
|
|
|
use SimpleSAML\XMLSchema\Exception\SchemaViolationException; |
13
|
|
|
use SimpleSAML\XMLSchema\XML\Constants\NS; |
14
|
|
|
use SimpleSAML\XMLSecurity\Constants as C; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Abstract class representing a dsig11:FieldIDType |
18
|
|
|
* |
19
|
|
|
* @package simplesaml/xml-security |
20
|
|
|
*/ |
21
|
|
|
abstract class AbstractFieldIDType extends AbstractDsig11Element |
22
|
|
|
{ |
23
|
|
|
// We use our own getter instead of the trait's one, so we prevent their use by marking them private |
24
|
|
|
use ExtendableElementTrait { |
25
|
|
|
getElements as private; |
26
|
|
|
setElements as private; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** @var string */ |
31
|
|
|
public const XS_ANY_ELT_NAMESPACE = NS::OTHER; |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Initialize a FieldIDType element. |
36
|
|
|
* |
37
|
|
|
* @param \SimpleSAML\XML\SerializableElementInterface $fieldId |
38
|
|
|
*/ |
39
|
|
|
public function __construct( |
40
|
|
|
protected Prime|TnB|PnB|GnB|SerializableElementInterface $fieldId, |
41
|
|
|
) { |
42
|
|
|
/** @var \SimpleSAML\XML\AbstractElement|\SimpleSAML\XML\Chunk $fieldId */ |
43
|
|
|
if ( |
44
|
|
|
!($fieldId instanceof Prime |
45
|
|
|
|| $fieldId instanceof TnB |
46
|
|
|
|| $fieldId instanceof PnB |
47
|
|
|
|| $fieldId instanceof GnB) |
48
|
|
|
) { |
49
|
|
|
Assert::true( |
50
|
|
|
(($fieldId instanceof Chunk) ? $fieldId->getNamespaceURI() : $fieldId::getNameSpaceURI()) |
51
|
|
|
!== C::NS_XDSIG11, |
52
|
|
|
'A <dsig11:FieldIDType> requires either a Prime, TnB, PnB, GnB or an element in namespace ##other', |
53
|
|
|
SchemaViolationException::class, |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Collect the value of the fieldId-property |
61
|
|
|
* |
62
|
|
|
* @return (\SimpleSAML\XMLSecurity\XML\dsig11\Prime| |
|
|
|
|
63
|
|
|
* \SimpleSAML\XMLSecurity\XML\dsig11\TnB| |
64
|
|
|
* \SimpleSAML\XMLSecurity\XML\dsig11\PnB| |
65
|
|
|
* \SimpleSAML\XMLSecurity\XML\dsig11\GnB| |
66
|
|
|
* \SimpleSAML\XML\SerializableElementInterface) |
67
|
|
|
*/ |
68
|
|
|
public function getFieldId(): Prime|TnB|PnB|GnB|SerializableElementInterface |
69
|
|
|
{ |
70
|
|
|
return $this->fieldId; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Convert this FieldIDType element to XML. |
76
|
|
|
* |
77
|
|
|
* @param \DOMElement|null $parent The element we should append this FieldIDType element to. |
78
|
|
|
* @return \DOMElement |
79
|
|
|
*/ |
80
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
81
|
|
|
{ |
82
|
|
|
$e = $this->instantiateParentElement($parent); |
83
|
|
|
|
84
|
|
|
$this->getFieldId()->toXML($e); |
85
|
|
|
|
86
|
|
|
return $e; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|