From 2fbb08397714f1ce04fafd5cee5ee0b9ebae15a9 Mon Sep 17 00:00:00 2001
From: Mads Freek Petersen <freek@wayf.dk>
Date: Mon, 14 Jul 2008 09:44:24 +0000
Subject: [PATCH] Emit the elements in <EncryptedData> (<EncryptionMethod>,
 <KeyInfo>, <CipherData>) in the sequence required by the spec.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@783 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/xmlseclibs.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/xmlseclibs.php b/lib/xmlseclibs.php
index 3d0266590..2ffe1d8f3 100644
--- a/lib/xmlseclibs.php
+++ b/lib/xmlseclibs.php
@@ -1272,7 +1272,7 @@ class XMLSecEnc {
 
         $encMethod = $this->encdoc->documentElement->appendChild($this->encdoc->createElementNS(XMLSecEnc::XMLENCNS, 'xenc:EncryptionMethod'));
         $encMethod->setAttribute('Algorithm', $objKey->getAlgorith());
-        $cipherValue->parentNode->parentNode->insertBefore($encMethod, $cipherValue->parentNode);
+        $cipherValue->parentNode->parentNode->insertBefore($encMethod, $cipherValue->parentNode->parentNode->firstChild);
 
         $strEncrypt = base64_encode($objKey->encryptData($data));
         $value = $this->encdoc->createTextNode($strEncrypt);
@@ -1360,7 +1360,7 @@ class XMLSecEnc {
         $root = $this->encdoc->documentElement;
         $encKey = $this->encdoc->createElementNS(XMLSecEnc::XMLENCNS, 'xenc:EncryptedKey');
         if ($append) {
-            $keyInfo = $root->appendChild($this->encdoc->createElementNS('http://www.w3.org/2000/09/xmldsig#', 'dsig:KeyInfo'));
+            $keyInfo = $root->insertBefore($this->encdoc->createElementNS('http://www.w3.org/2000/09/xmldsig#', 'dsig:KeyInfo'), $root->firstChild);
             $keyInfo->appendChild($encKey);
         } else {
             $this->encKey = $encKey;
-- 
GitLab