| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace SimpleSAML\XMLSecurity\XML\xenc11; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use DOMElement; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use SimpleSAML\XML\SchemaValidatableElementInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use SimpleSAML\XML\SchemaValidatableElementTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use SimpleSAML\XMLSchema\Exception\TooManyElementsException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use SimpleSAML\XMLSchema\Type\AnyURIValue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use SimpleSAML\XMLSchema\Type\IDValue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use SimpleSAML\XMLSchema\Type\StringValue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use SimpleSAML\XMLSecurity\Assert\Assert; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use SimpleSAML\XMLSecurity\XML\xenc\ReferenceList; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use function array_pop; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use function strval; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * Class representing <xenc11:DerivedKeyType>. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * @package simplesamlphp/xml-security | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | abstract class AbstractDerivedKeyType extends AbstractXenc11Element implements | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     SchemaValidatableElementInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     use SchemaValidatableElementTrait; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * DerivedKey constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @param \SimpleSAML\XMLSchema\Type\StringValue|null $recipient | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @param \SimpleSAML\XMLSchema\Type\IDValue|null $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * @param \SimpleSAML\XMLSchema\Type\AnyURIValue|null $type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @param \SimpleSAML\XMLSecurity\XML\xenc11\KeyDerivationMethod|null $keyDerivationMethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @param \SimpleSAML\XMLSecurity\XML\xenc\ReferenceList|null $referenceList | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * @param \SimpleSAML\XMLSecurity\XML\xenc11\DerivedKeyName|null $derivedKeyName | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @param \SimpleSAML\XMLSecurity\XML\xenc11\MasterKeyName|null $masterKeyName | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     final public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         protected ?StringValue $recipient = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         protected ?IDValue $id = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         protected ?AnyURIValue $type = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         protected ?KeyDerivationMethod $keyDerivationMethod = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         protected ?ReferenceList $referenceList = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         protected ?DerivedKeyName $derivedKeyName = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         protected ?MasterKeyName $masterKeyName = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * Get the value of the $recipient property. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @return \SimpleSAML\XMLSchema\Type\StringValue|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     public function getRecipient(): ?StringValue | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         return $this->recipient; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * Get the value of the $id property. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * @return \SimpleSAML\XMLSchema\Type\IDValue|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     public function getId(): ?IDValue | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         return $this->id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * Get the value of the $type property. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * @return \SimpleSAML\XMLSchema\Type\AnyURIValue|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     public function getType(): ?AnyURIValue | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         return $this->type; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * Get the value of the $keyDerivationMethod property. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * @return \SimpleSAML\XMLSecurity\XML\xenc11\KeyDerivationMethod|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     public function getKeyDerivationMethod(): ?KeyDerivationMethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         return $this->keyDerivationMethod; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      * Get the value of the $referenceList property. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      * @return \SimpleSAML\XMLSecurity\XML\xenc\ReferenceList|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     public function getReferenceList(): ?ReferenceList | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         return $this->referenceList; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      * Get the value of the $derivedKeyName property. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |      * @return \SimpleSAML\XMLSecurity\XML\xenc11\DerivedKeyName|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     public function getDerivedKeyName(): ?DerivedKeyName | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         return $this->derivedKeyName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |      * Get the value of the $masterKeyName property. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |      * @return \SimpleSAML\XMLSecurity\XML\xenc11\MasterKeyName|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |     public function getMasterKeyName(): ?MasterKeyName | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         return $this->masterKeyName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |      * Test if an object, at the state it's in, would produce an empty XML-element | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |     public function isEmptyElement(): bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         return empty($this->getKeyDerivationMethod()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |             && empty($this->getReferenceList()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |             && empty($this->getDerivedKeyName()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |             && empty($this->getMasterKeyName()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |             && empty($this->getRecipient()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |             && empty($this->getId()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |             && empty($this->getType()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |      * @inheritDoc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |      * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |      *   If the qualified name of the supplied element is wrong | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 154 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 155 |  |  |     public static function fromXML(DOMElement $xml): static | 
            
                                                                        
                            
            
                                    
            
            
                | 156 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 157 |  |  |         Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); | 
            
                                                                        
                            
            
                                    
            
            
                | 158 |  |  |         Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); | 
            
                                                                        
                            
            
                                    
            
            
                | 159 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 160 |  |  |         $keyDerivationMethod = KeyDerivationMethod::getChildrenOfClass($xml); | 
            
                                                                        
                            
            
                                    
            
            
                | 161 |  |  |         Assert::maxCount($keyDerivationMethod, 1, TooManyElementsException::class); | 
            
                                                                        
                            
            
                                    
            
            
                | 162 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 163 |  |  |         $referenceList = ReferenceList::getChildrenOfClass($xml); | 
            
                                                                        
                            
            
                                    
            
            
                | 164 |  |  |         Assert::maxCount($referenceList, 1, TooManyElementsException::class); | 
            
                                                                        
                            
            
                                    
            
            
                | 165 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 166 |  |  |         $derivedKeyName = DerivedKeyName::getChildrenOfClass($xml); | 
            
                                                                        
                            
            
                                    
            
            
                | 167 |  |  |         Assert::maxCount($derivedKeyName, 1, TooManyElementsException::class); | 
            
                                                                        
                            
            
                                    
            
            
                | 168 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 169 |  |  |         $masterKeyName = MasterKeyName::getChildrenOfClass($xml); | 
            
                                                                        
                            
            
                                    
            
            
                | 170 |  |  |         Assert::maxCount($masterKeyName, 1, TooManyElementsException::class); | 
            
                                                                        
                            
            
                                    
            
            
                | 171 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 172 |  |  |         return new static( | 
            
                                                                        
                            
            
                                    
            
            
                | 173 |  |  |             self::getOptionalAttribute($xml, 'Recipient', StringValue::class, null), | 
            
                                                                        
                            
            
                                    
            
            
                | 174 |  |  |             self::getOptionalAttribute($xml, 'Id', IDValue::class, null), | 
            
                                                                        
                            
            
                                    
            
            
                | 175 |  |  |             self::getOptionalAttribute($xml, 'Type', AnyURIValue::class, null), | 
            
                                                                        
                            
            
                                    
            
            
                | 176 |  |  |             array_pop($keyDerivationMethod), | 
            
                                                                        
                            
            
                                    
            
            
                | 177 |  |  |             array_pop($referenceList), | 
            
                                                                        
                            
            
                                    
            
            
                | 178 |  |  |             array_pop($derivedKeyName), | 
            
                                                                        
                            
            
                                    
            
            
                | 179 |  |  |             array_pop($masterKeyName), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |      * @inheritDoc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |     public function toXML(?DOMElement $parent = null): DOMElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |         $e = $this->instantiateParentElement($parent); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |         if ($this->getRecipient() !== null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |             $e->setAttribute('Recipient', strval($this->getRecipient())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |         if ($this->getId() !== null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |             $e->setAttribute('Id', strval($this->getId())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |         if ($this->getType() !== null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |             $e->setAttribute('Type', strval($this->getType())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |         $this->getKeyDerivationMethod()?->toXML($e); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |         $this->getReferenceList()?->toXML($e); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |         $this->getDerivedKeyName()?->toXML($e); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |         $this->getMasterKeyName()?->toXML($e); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |         return $e; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 210 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 211 |  |  |  |