New KeyResolver/Validator/Encrypter/Decrypter classes.
[shibboleth/cpp-xmltooling.git] / xmltooling / signature / KeyResolver.h
1 /*\r
2  *  Copyright 2001-2006 Internet2\r
3  * \r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 /**\r
18  * @file KeyResolver.h\r
19  * \r
20  * Resolves keys based on KeyInfo information or other external factors. \r
21  */\r
22 \r
23 #if !defined(__xmltooling_keyres_h__) && !defined(XMLTOOLING_NO_XMLSEC)\r
24 #define __xmltooling_keyres_h__\r
25 \r
26 #include <xmltooling/signature/KeyInfo.h>\r
27 \r
28 #include <xsec/dsig/DSIGKeyInfoList.hpp>\r
29 #include <xsec/enc/XSECCryptoKey.hpp>\r
30 \r
31 namespace xmlsignature {\r
32 \r
33     /**\r
34      * An API for resolving decryption keys.\r
35      * Can be used during both data and key decryption.\r
36      */\r
37     class XMLTOOL_API KeyResolver {\r
38     public:\r
39         /**\r
40          * Constructor based on a single externally supplied decryption key.\r
41          * The key will be destroyed when the resolver is. \r
42          * \r
43          * @param key   external decryption key\r
44          */\r
45         KeyResolver(XSECCryptoKey* key=NULL) : m_key(key) {}\r
46         \r
47         virtual ~KeyResolver() {\r
48             delete m_key;\r
49         }\r
50         \r
51         /**\r
52          * Returns a key based on the supplied KeyInfo information.\r
53          * The caller must delete the key when done with it.\r
54          * \r
55          * @param keyInfo   the key information\r
56          * @return  the resolved key\r
57          */\r
58         virtual XSECCryptoKey* resolveKey(KeyInfo* keyInfo) {\r
59             return m_key ? m_key->clone() : NULL;\r
60         }\r
61 \r
62         /**\r
63          * Returns a key based on the supplied KeyInfo information.\r
64          * The caller must delete the key when done with it.\r
65          * \r
66          * @param keyInfo   the key information\r
67          * @return  the resolved key\r
68          */\r
69         virtual XSECCryptoKey* resolveKey(DSIGKeyInfoList* keyInfo=NULL) {\r
70             return m_key ? m_key->clone() : NULL;\r
71         }\r
72         \r
73         /**\r
74          * Creates a copy of the resolver.\r
75          * \r
76          * @return the cloned resolver\r
77          */\r
78         virtual KeyResolver* clone() const {\r
79             return new KeyResolver(m_key ? m_key->clone() : NULL);\r
80         }\r
81         \r
82     protected:\r
83         XSECCryptoKey* m_key;\r
84     };\r
85 \r
86 };\r
87 \r
88 #endif /* __xmltooling_keyres_h__ */\r