@@ -70,16 +70,16 @@ class XMLSecEnc
7070 /** @var string */
7171 public const XMLENCNS = 'http://www.w3.org/2001/04/xmlenc# ' ;
7272
73- /** @var null| \DOMDocument */
73+ /** @var \DOMDocument|null */
7474 private $ encdoc = null ;
7575
76- /** @var null| \DOMNode */
76+ /** @var \DOMNode|null */
7777 private $ rawNode = null ;
7878
79- /** @var null| string */
79+ /** @var string|null */
8080 public $ type = null ;
8181
82- /** @var null| \DOMElement */
82+ /** @var \DOMElement|null */
8383 public $ encKey = null ;
8484
8585 /** @var array */
@@ -111,10 +111,6 @@ private function resetTemplate(): void
111111 */
112112 public function addReference (string $ name , DOMNode $ node , string $ type ): void
113113 {
114- if (!($ node instanceof DOMNode)) {
115- throw new Exception ('$node is not of type DOMNode ' );
116- }
117-
118114 $ curencdoc = $ this ->encdoc ;
119115 $ this ->resetTemplate ();
120116 $ encdoc = $ this ->encdoc ;
@@ -143,24 +139,28 @@ public function setNode(DOMNode $node): void
143139 * @param bool $replace Whether the encrypted node should be replaced in the original tree. Default is true.
144140 * @throws \Exception
145141 *
146- * @return \DOMElement The <xenc:EncryptedData>-element.
142+ * @return \DOMNode|false The <xenc:EncryptedData>-element.
147143 */
148- public function encryptNode (XMLSecurityKey $ objKey , bool $ replace = true ): DOMElement
144+ public function encryptNode (XMLSecurityKey $ objKey , bool $ replace = true )
149145 {
150146 $ data = '' ;
151147 if (empty ($ this ->rawNode )) {
152148 throw new Exception ('Node to encrypt has not been set ' );
153149 }
150+
154151 if (!($ objKey instanceof XMLSecurityKey)) {
155152 throw new Exception ('Invalid Key ' );
156153 }
154+
157155 $ doc = $ this ->rawNode ->ownerDocument ;
158156 $ xPath = new DOMXPath ($ this ->encdoc );
159157 $ objList = $ xPath ->query ('/xenc:EncryptedData/xenc:CipherData/xenc:CipherValue ' );
158+
160159 $ cipherValue = $ objList ->item (0 );
161160 if ($ cipherValue == null ) {
162161 throw new Exception ('Error locating CipherValue element within template ' );
163162 }
163+
164164 switch ($ this ->type ) {
165165 case (self ::ELEMENT ):
166166 $ data = $ doc ->saveXML ($ this ->rawNode );
@@ -556,7 +556,7 @@ public static function staticLocateKeyInfo(XMLSecurityKey $objBaseKey = null, DO
556556 * @param \DOMNode|null $node
557557 * @return \RobRichards\XMLSecLibs\XMLSecurityKey|null
558558 */
559- public function locateKeyInfo (XMLSecurityKey $ objBaseKey = null , DOMNode $ node = null ): XMLSecurityKey
559+ public function locateKeyInfo (XMLSecurityKey $ objBaseKey = null , DOMNode $ node = null ): ? XMLSecurityKey
560560 {
561561 if (empty ($ node )) {
562562 $ node = $ this ->rawNode ;
0 commit comments