56ade75051fb3dfe7c4c87031db91c7c04288f9b
[shibboleth/cpp-xmltooling.git] / xmltooling / security / KeyInfoResolver.h
1 /*
2  *  Copyright 2001-2007 Internet2
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file xmltooling/security/KeyInfoResolver.h
19  * 
20  * Resolves credentials from KeyInfo information.
21  */
22
23 #if !defined(__xmltooling_keyres_h__) && !defined(XMLTOOLING_NO_XMLSEC)
24 #define __xmltooling_keyres_h__
25
26 #include <xmltooling/security/Credential.h>
27 #include <xmltooling/security/CredentialCriteria.h>
28 #include <xmltooling/security/KeyInfoCredentialContext.h>
29
30 #include <xsec/dsig/DSIGKeyInfoList.hpp>
31
32 namespace xmltooling {
33
34     /**
35      * Resolves credentials from KeyInfo information.
36      *
37      * <p>Credential-specific bitmasks can be provided to control what to resolve.
38      *
39      * <p>Implementations should only establish KeyNames on the basis of explicit names
40      * within the KeyInfo object, never by extracting names out of physical credentials
41      * found within it.
42      */
43     class XMLTOOL_API KeyInfoResolver {
44         MAKE_NONCOPYABLE(KeyInfoResolver);
45     protected:
46         KeyInfoResolver() {}
47     public:
48         virtual ~KeyInfoResolver() {}
49         
50         /**
51          * Returns a credential based on the supplied KeyInfo information.
52          * The caller must release the credential when done with it.
53          * 
54          * @param keyInfo   the key information
55          * @param types     types of credentials to resolve, or 0 for any/all
56          * @return  the resolved credential, or NULL
57          */
58         virtual Credential* resolve(const xmlsignature::KeyInfo* keyInfo, int types=0) const=0;
59
60         /**
61          * Returns a credential based on the supplied KeyInfo information.
62          * The caller must release the credential when done with it.
63          * 
64          * @param keyInfo   the key information
65          * @param types     types of credentials to resolve, or 0 for any/all
66          * @return  the resolved credential, or NULL
67          */
68         virtual Credential* resolve(DSIGKeyInfoList* keyInfo, int types=0) const=0;
69
70         /**
71          * Returns a credential based on the KeyInfo information in the supplied
72          * context. The caller must release the credential when done with it.
73          *
74          * <p>The context object will be owned by the Credential and freed with it.
75          * 
76          * @param context   context containing the key information
77          * @param types types of credentials to resolve, or 0 for any/all
78          * @return  the resolved credential, or NULL
79          */
80         virtual Credential* resolve(KeyInfoCredentialContext* context, int types=0) const=0;
81
82         /**
83          * Returns a credential based on the supplied KeyInfo information.
84          * The caller must release the credential when done with it.
85          * 
86          * @param sig   signature containing the key information
87          * @param types types of credentials to resolve, or 0 for any/all
88          * @return  the resolved credential, or NULL
89          */
90         Credential* resolve(const xmlsignature::Signature* sig, int types=0) const;
91
92         /**
93          * Returns a credential based on the KeyInfo information in the supplied
94          * criteria. The caller must release the credential when done with it.
95          * 
96          * @param criteria   criteria containing the key information
97          * @param types types of credentials to resolve, or 0 for any/all
98          * @return  the resolved credential, or NULL
99          */
100         Credential* resolve(const CredentialCriteria& criteria, int types=0) const;
101     };
102
103     /**
104      * Registers KeyInfoResolver classes into the runtime.
105      */
106     void XMLTOOL_API registerKeyInfoResolvers();
107
108     /** KeyInfoResolver based on extracting by value directly out of a KeyInfo */
109     #define INLINE_KEYINFO_RESOLVER  "Inline"
110 };
111
112 #endif /* __xmltooling_keyres_h__ */