Convert from NULL macro to nullptr, remove unused zlib code.
[shibboleth/cpp-opensaml.git] / saml / saml2 / core / impl / Assertions.cpp
index 6dbd6c8..d86d140 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2009 Internet2
+ *  Copyright 2001-2010 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -34,6 +34,8 @@
 #include <xmltooling/encryption/Encrypter.h>
 #include <xmltooling/encryption/Decrypter.h>
 #include <xmltooling/security/Credential.h>
+#include <xmltooling/signature/KeyInfo.h>
+#include <xmltooling/util/ParserPool.h>
 
 #include <xsec/utils/XSECPlatformUtils.hpp>
 
@@ -71,7 +73,7 @@ void EncryptedElementType::encrypt(
         algorithm = DSIGConstants::s_unicodeStrURIAES256_CBC;
 
     Encrypter encrypter;
-    Encrypter::EncryptionParams ep(algorithm, NULL, 0, NULL, compact);
+    Encrypter::EncryptionParams ep(algorithm, nullptr, 0, nullptr, compact);
     Encrypter::KeyEncryptionParams kep(*KEK);
     setEncryptedData(encrypter.encryptElement(xmlObject.getDOM(),ep,&kep));
 }
@@ -93,7 +95,7 @@ void EncryptedElementType::encrypt(
     if (XSECPlatformUtils::g_cryptoProvider->getRandom(keyBuffer,32)<32)
         throw EncryptionException("Unable to generate encryption key; was PRNG seeded?");
     Encrypter encrypter;
-    Encrypter::EncryptionParams ep(algorithm, keyBuffer, 32, NULL, compact);
+    Encrypter::EncryptionParams ep(algorithm, keyBuffer, 32, nullptr, compact);
     setEncryptedData(encrypter.encryptElement(xmlObject.getDOM(),ep));
     getEncryptedData()->setId(SAMLConfig::getConfig().generateIdentifier());
 
@@ -162,7 +164,18 @@ XMLObject* EncryptedElementType::decrypt(const CredentialResolver& credResolver,
         if (plaintext->getNodeType()==DOMNode::ELEMENT_NODE) {
             // Import the tree into a new Document that we can bind to the unmarshalled object.
             XercesJanitor<DOMDocument> newdoc(XMLToolingConfig::getConfig().getParser().newDocument());
-            DOMElement* treecopy = static_cast<DOMElement*>(newdoc->importNode(plaintext, true));
+            DOMElement* treecopy;
+            try {
+                treecopy = static_cast<DOMElement*>(newdoc->importNode(plaintext, true));
+            }
+            catch (XMLException& ex) {
+                frag->release();
+                auto_ptr_char temp(ex.getMessage());
+                throw DecryptionException(
+                    string("Error importing decypted DOM into new document: ") + (temp.get() ? temp.get() : "no message")
+                    );
+            }
+            frag->release();
             newdoc->appendChild(treecopy);
             auto_ptr<XMLObject> ret(XMLObjectBuilder::buildOneFromElement(treecopy, true));
             newdoc.release();