Convert from NULL macro to nullptr.
[shibboleth/cpp-xmltooling.git] / xmltooling / encryption / Decrypter.h
index 49b3875..1a3ddc0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2007 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.
 #if !defined(__xmltooling_decrypter_h__) && !defined(XMLTOOLING_NO_XMLSEC)
 #define __xmltooling_decrypter_h__
 
-#include <xmltooling/encryption/Encryption.h>
-#include <xmltooling/signature/KeyResolver.h>
+#include <xmltooling/exceptions.h>
 
-#include <xsec/enc/XSECCryptoKey.hpp>
-#include <xsec/xenc/XENCCipher.hpp>
+class XENCCipher;
+class XSECCryptoKey;
+
+namespace xmltooling {
+    class XMLTOOL_API CredentialCriteria;
+    class XMLTOOL_API CredentialResolver;
+};
 
 namespace xmlencryption {
 
+    class XMLTOOL_API EncryptedData;
+    class XMLTOOL_API EncryptedKey;
+    class XMLTOOL_API EncryptedKeyResolver;
+
     /**
      * Wrapper API for XML Decryption functionality.
      */
@@ -39,36 +47,50 @@ namespace xmlencryption {
     public:
         /**
          * Constructor.
-         * Resolvers will be deleted when Decrypter is.
          * 
-         * @param KEKresolver   resolves key decryption key
-         * @param resolver      resolves data decryption key
+         * @param credResolver  locked credential resolver to supply decryption keys
+         * @param criteria      optional external criteria to use with resolver
+         * @param EKResolver    locates an EncryptedKey pertaining to the EncryptedData
          */
-        Decrypter(xmlsignature::KeyResolver* KEKresolver=NULL, xmlsignature::KeyResolver* resolver=NULL)
-            : m_cipher(NULL), m_resolver(resolver), m_KEKresolver(KEKresolver) {
-        }
+        Decrypter(
+            const xmltooling::CredentialResolver* credResolver=nullptr,
+            xmltooling::CredentialCriteria* criteria=nullptr,
+            const EncryptedKeyResolver* EKResolver=nullptr
+            );
 
-        ~Decrypter();
+        virtual ~Decrypter();
         
         /**
-         * Replace the current data encryption KeyResolver interface, if any, with a new one.
+         * Replace the current EncryptedKeyResolver interface, if any, with a new one.
+         * 
+         * @param EKResolver  the EncryptedKeyResolver to attach 
+         */
+        void setEncryptedKeyResolver(const EncryptedKeyResolver* EKResolver);
+
+        /**
+         * Replace the current CredentialResolver interface, if any, with a new one.
          * 
-         * @param resolver  the KeyResolver to attach 
+         * @param resolver  the locked CredentialResolver to attach, or nullptr to clear
+         * @param criteria  optional external criteria to use with resolver
          */
-        void setKeyResolver(xmlsignature::KeyResolver* resolver) {
-            delete m_resolver;
-            m_resolver=resolver;
-        }
+        void setKEKResolver(const xmltooling::CredentialResolver* resolver, xmltooling::CredentialCriteria* criteria);
 
         /**
-         * Replace the current key encryption KeyResolver interface, if any, with a new one.
+         * Decrypts the supplied information using the supplied key, and returns
+         * the resulting as a DOM fragment owned by the document associated with the
+         * marshalled EncryptedData object.
+         * 
+         * Note that the DOM nodes will be invalidated once that document
+         * is released. The caller should therefore process the DOM fragment as
+         * required and drop all references to it before that happens. The usual
+         * approach should be to unmarshall the DOM and then release it, or the
+         * DOM can also be imported into a separately owned document.
          * 
-         * @param resolver  the KeyResolver to attach 
+         * @param encryptedData the data to decrypt
+         * @param key           the decryption key to use (it will not be freed internally)
+         * @return  the decrypted DOM fragment
          */
-        void setKEKResolver(xmlsignature::KeyResolver* resolver) {
-            delete m_KEKresolver;
-            m_KEKresolver=resolver;
-        }
+        xercesc::DOMDocumentFragment* decryptData(const EncryptedData& encryptedData, XSECCryptoKey* key);
 
         /**
          * Decrypts the supplied information and returns the resulting as a DOM
@@ -81,12 +103,31 @@ namespace xmlencryption {
          * approach should be to unmarshall the DOM and then release it, or the
          * DOM can also be imported into a separately owned document.
          * 
-         * @param encryptedData the encrypted data to decrypt
+         * @param encryptedData the data to decrypt
+         * @param recipient identifier of decrypting entity for use in identifying multi-cast keys
          * @return  the decrypted DOM fragment
          */
-        DOMDocumentFragment* decryptData(EncryptedData* encryptedData);
+        xercesc::DOMDocumentFragment* decryptData(const EncryptedData& encryptedData, const XMLCh* recipient=nullptr);
         
         /**
+         * Decrypts the supplied information to an output stream.
+         *
+         * @param out           output stream to receive the decrypted data 
+         * @param encryptedData the data to decrypt
+         * @param key           the decryption key to use (it will not be freed internally)
+         */
+        void decryptData(std::ostream& out, const EncryptedData& encryptedData, XSECCryptoKey* key);
+
+        /**
+         * Decrypts the supplied information to an output stream.
+         *
+         * @param out           output stream to receive the decrypted data 
+         * @param encryptedData the data to decrypt
+         * @param recipient     identifier of decrypting entity for use in identifying multi-cast keys
+         */
+        void decryptData(std::ostream& out, const EncryptedData& encryptedData, const XMLCh* recipient=nullptr);
+
+        /**
          * Decrypts the supplied information and returns the resulting key.
          * The caller is responsible for deleting the key. The algorithm of the
          * key must be supplied by the caller based on knowledge of the associated
@@ -96,12 +137,13 @@ namespace xmlencryption {
          * @param algorithm     the algorithm associated with the decrypted key
          * @return  the decrypted key
          */
-        XSECCryptoKey* decryptKey(EncryptedKey* encryptedKey, const XMLCh* algorithm);
+        XSECCryptoKey* decryptKey(const EncryptedKey& encryptedKey, const XMLCh* algorithm);
         
     private:
         XENCCipher* m_cipher;
-        xmlsignature::KeyResolver* m_resolver;
-        xmlsignature::KeyResolver* m_KEKresolver;
+        const xmltooling::CredentialResolver* m_credResolver;
+        xmltooling::CredentialCriteria* m_criteria;
+        const EncryptedKeyResolver* m_EKResolver;
     };
 
     DECL_XMLTOOLING_EXCEPTION(DecryptionException,XMLTOOL_EXCEPTIONAPI(XMLTOOL_API),xmlencryption,xmltooling::XMLToolingException,Exceptions in decryption processing);