55namespace SimpleSAML \XMLSecurity \XML \dsig11 ;
66
77use DOMElement ;
8+ use SimpleSAML \Assert \Assert ;
9+ use SimpleSAML \XML \Chunk ;
10+ use SimpleSAML \XML \Constants as C ;
11+ use SimpleSAML \XML \Exception \SchemaViolationException ;
812use SimpleSAML \XML \ExtendableElementTrait ;
13+ use SimpleSAML \XML \SerializableElementInterface ;
914use SimpleSAML \XML \XsNamespace as NS ;
1015
1116/**
1520 */
1621abstract class AbstractFieldIDType extends AbstractDsig11Element
1722{
18- use ExtendableElementTrait;
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+ }
1928
2029 /** @var \SimpleSAML\XML\XsNamespace */
2130 public const XS_ANY_ELT_NAMESPACE = NS ::OTHER ;
@@ -24,64 +33,39 @@ abstract class AbstractFieldIDType extends AbstractDsig11Element
2433 /**
2534 * Initialize a FieldIDType element.
2635 *
27- * @param \SimpleSAML\XMLSecurity\XML\dsig11\Prime $prime
28- * @param \SimpleSAML\XMLSecurity\XML\dsig11\TnB $tnb
29- * @param \SimpleSAML\XMLSecurity\XML\dsig11\PnB $pnb
30- * @param \SimpleSAML\XMLSecurity\XML\dsig11\GnB $gnb
31- * @param array<\SimpleSAML\XML\SerializableElementInterface> $children
36+ * @param \SimpleSAML\XML\SerializableElementInterface $fieldId
3237 */
3338 public function __construct (
34- protected Prime $ prime ,
35- protected TnB $ tnb ,
36- protected PnB $ pnb ,
37- protected GnB $ gnb ,
38- array $ children ,
39+ protected Prime |TnB |PnB |GnB |SerializableElementInterface $ fieldId ,
3940 ) {
40- $ this ->setElements ($ children );
41+ if (
42+ !($ fieldId instanceof Prime
43+ || $ fieldId instanceof TnB
44+ || $ fieldId instanceof PnB
45+ || $ fieldId instanceof GnB)
46+ ) {
47+ Assert::true (
48+ (($ fieldId instanceof Chunk) ? $ fieldId ->getNamespaceURI () : $ fieldId ::getNameSpaceURI ())
49+ !== C::NS_XDSIG11 ,
50+ 'A <dsig11:FieldIDType> requires either a Prime, TnB, PnB, GnB or an element in namespace ##other ' ,
51+ SchemaViolationException::class,
52+ );
53+ }
4154 }
4255
4356
4457 /**
45- * Collect the value of the prime -property
58+ * Collect the value of the fieldId -property
4659 *
4760 * @return \SimpleSAML\XMLSecurity\XML\dsig11\Prime
61+ * \SimpleSAML\XMLSecurity\XML\dsig11\TnB
62+ * \SimpleSAML\XMLSecurity\XML\dsig11\PnB
63+ * \SimpleSAML\XMLSecurity\XML\dsig11\GnB
64+ * \SimpleSAML\XML\SerializableElementInterface
4865 */
49- public function getPrime (): Prime
66+ public function getFieldId (): Prime | TnB | PnB | GnB | SerializableElementInterface
5067 {
51- return $ this ->prime ;
52- }
53-
54-
55- /**
56- * Collect the value of the tnb-property
57- *
58- * @return \SimpleSAML\XMLSecurity\XML\dsig11\TnB
59- */
60- public function getTnB (): TnB
61- {
62- return $ this ->tnb ;
63- }
64-
65-
66- /**
67- * Collect the value of the pnb-property
68- *
69- * @return \SimpleSAML\XMLSecurity\XML\dsig11\PnB
70- */
71- public function getPnB (): PnB
72- {
73- return $ this ->pnb ;
74- }
75-
76-
77- /**
78- * Collect the value of the gnb-property
79- *
80- * @return \SimpleSAML\XMLSecurity\XML\dsig11\GnB
81- */
82- public function getGnB (): GnB
83- {
84- return $ this ->gnb ;
68+ return $ this ->fieldId ;
8569 }
8670
8771
@@ -95,14 +79,7 @@ public function toXML(?DOMElement $parent = null): DOMElement
9579 {
9680 $ e = $ this ->instantiateParentElement ($ parent );
9781
98- $ this ->getPrime ()->toXML ($ e );
99- $ this ->getTnB ()->toXML ($ e );
100- $ this ->getPnB ()->toXML ($ e );
101- $ this ->getGnB ()->toXML ($ e );
102-
103- foreach ($ this ->getElements () as $ elt ) {
104- $ elt ->toXML ($ e );
105- }
82+ $ this ->getFieldId ()->toXML ($ e );
10683
10784 return $ e ;
10885 }
0 commit comments