7d060c62cf634d8b1865948180bc1c0bbc0154f2
[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 keys.\r
35      */\r
36     class XMLTOOL_API KeyResolver {\r
37     public:\r
38         /**\r
39          * Constructor based on a single externally supplied key.\r
40          * The key will be destroyed when the resolver is. \r
41          * \r
42          * @param key   external key\r
43          */\r
44         KeyResolver(XSECCryptoKey* key=NULL) : m_key(key) {}\r
45         \r
46         virtual ~KeyResolver() {\r
47             delete m_key;\r
48         }\r
49         \r
50         /**\r
51          * Returns a key based on the supplied KeyInfo information.\r
52          * The caller must delete the key when done with it.\r
53          * \r
54          * @param keyInfo   the key information\r
55          * @return  the resolved key\r
56          */\r
57         virtual XSECCryptoKey* resolveKey(KeyInfo* keyInfo) {\r
58             return m_key ? m_key->clone() : NULL;\r
59         }\r
60 \r
61         /**\r
62          * Returns a key based on the supplied KeyInfo information.\r
63          * The caller must delete the key when done with it.\r
64          * \r
65          * @param keyInfo   the key information\r
66          * @return  the resolved key\r
67          */\r
68         virtual XSECCryptoKey* resolveKey(DSIGKeyInfoList* keyInfo=NULL) {\r
69             return m_key ? m_key->clone() : NULL;\r
70         }\r
71         \r
72         /**\r
73          * Creates a copy of the resolver.\r
74          * \r
75          * @return the cloned resolver\r
76          */\r
77         virtual KeyResolver* clone() const {\r
78             return new KeyResolver(m_key ? m_key->clone() : NULL);\r
79         }\r
80         \r
81     protected:\r
82         XSECCryptoKey* m_key;\r
83     };\r
84 \r
85 };\r
86 \r
87 #endif /* __xmltooling_keyres_h__ */\r