Revised decryption APIs to clarify CredentialResolver/KeyResolver difference.
[shibboleth/cpp-xmltooling.git] / xmltooling / security / CredentialResolver.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/signature/CredentialResolver.h
19  * 
20  * Resolves keys and certificates "owned" by an entity 
21  */
22
23 #if !defined(__xmltooling_credres_h__) && !defined(XMLTOOLING_NO_XMLSEC)
24 #define __xmltooling_credres_h__
25
26 #include <xmltooling/Lockable.h>
27
28 #include <vector>
29 #include <xsec/enc/XSECCryptoKey.hpp>
30 #include <xsec/enc/XSECCryptoX509.hpp>
31
32 namespace xmlsignature {
33     class XMLTOOL_API KeyInfo;
34 };
35
36 namespace xmltooling {
37
38     /**
39      * An API for resolving local/owned keys and certificates
40      */
41     class XMLTOOL_API CredentialResolver : public Lockable
42     {
43         MAKE_NONCOPYABLE(CredentialResolver);
44     protected:
45         CredentialResolver() {}
46         
47     public:
48         virtual ~CredentialResolver() {}
49         
50         /**
51          * Returns a secret or private key to use for signing or decryption operations.
52          * The caller is responsible for deleting the key when finished with it.
53          * 
54          * @param keyInfo   optional material identifying a decryption key 
55          * @return  a secret or private key
56          */
57         virtual XSECCryptoKey* getKey(const xmlsignature::KeyInfo* keyInfo=NULL) const=0;
58         
59         /**
60          * Returns a set of certificates to publish during signing operations.
61          * The certificates must be cloned if kept beyond the scope of a lock.
62          * 
63          * @return  a set of certificates
64          */
65         virtual const std::vector<XSECCryptoX509*>& getCertificates() const=0;
66     };
67
68     /**
69      * Registers CredentialResolver classes into the runtime.
70      */
71     void XMLTOOL_API registerCredentialResolvers();
72
73     /** CredentialResolver based on local files */
74     #define FILESYSTEM_CREDENTIAL_RESOLVER  "File"
75 };
76
77 #endif /* __xmltooling_credres_h__ */