Major revamp of credential and trust handling code, PKIX engine still needs work.
[shibboleth/cpp-xmltooling.git] / xmltooling / security / Credential.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/Credential.h
19  * 
20  * Wraps keys and related functionality. 
21  */
22
23 #if !defined(__xmltooling_cred_h__) && !defined(XMLTOOLING_NO_XMLSEC)
24 #define __xmltooling_cred_h__
25
26 #include <xmltooling/base.h>
27
28 #include <xsec/enc/XSECCryptoKey.hpp>
29
30 namespace xmlsignature {
31     class XMLTOOL_API KeyInfo;
32 };
33
34 namespace xmltooling {
35
36     /**
37      * Wraps keys and related functionality.
38      *
39      * <p>Shared credential implementations should implement reference counting
40      * and honor any locking parameters to ensure appropriate synchronization.
41      */
42     class XMLTOOL_API Credential
43     {
44         MAKE_NONCOPYABLE(Credential);
45     protected:
46         Credential() {}
47         
48     public:
49         virtual ~Credential() {}
50         
51         enum ResolveTypes {
52             RESOLVE_KEYS = 1
53         };
54
55         /**
56          * Returns a secret or private key to use for signing or decryption operations.
57          * 
58          * @return  a secret or private key
59          */
60         virtual XSECCryptoKey* getPrivateKey() const=0;
61
62         /**
63          * Returns a secret or public key to use for verification or encryption operations.
64          * 
65          * @return  a secret or public key
66          */
67         virtual XSECCryptoKey* getPublicKey() const=0;
68         
69         /**
70          * Returns names representing the Credential, generally when the Credential itself merely
71          * points to a Credential rather than containing one.
72          * 
73          * @param results   array to populate with names
74          * @return  the number of names returned
75          */
76         virtual std::vector<std::string>::size_type getKeyNames(std::vector<std::string>& results) const=0;
77         
78         /**
79          * Returns a ds:KeyInfo object representing the Credential for use in
80          * communicating with other entities.
81          * 
82          * @param compact   true iff the communication medium is such that only compact forms should be included
83          * @return reference to a KeyInfo object
84          */
85         virtual const xmlsignature::KeyInfo* getKeyInfo(bool compact=false) const=0;
86
87         /**
88          * Compares the public key inside the Credential to a second public key.
89          *
90          * @param key   the public key to compare
91          * @return true iff the keys are equal
92          */
93         virtual bool isEqual(XSECCryptoKey& key) const;
94     };
95 };
96
97 #endif /* __xmltooling_cred_h__ */