c333b6779e9fb593df81d52494ff2ec85a4cc4ee
[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 #include <xsec/enc/XSECCryptoKey.hpp>
28
29 namespace xmlsignature {
30     class XMLTOOL_API KeyInfo;
31 };
32
33 namespace xmltooling {
34
35     /**
36      * Wraps keys and related functionality.
37      *
38      * <p>Shared credential implementations should implement reference counting
39      * and honor any locking parameters to ensure appropriate synchronization.
40      */
41     class XMLTOOL_API Credential
42     {
43         MAKE_NONCOPYABLE(Credential);
44     protected:
45         Credential() {}
46         
47     public:
48         virtual ~Credential() {}
49         
50         enum ResolveTypes {
51             RESOLVE_KEYS = 1
52         };
53
54         /**
55          * Returns an algorithm identifier for the Credential.
56          *
57          * @return  the Credential algorithm, or NULL if indeterminate
58          */
59         virtual const char* getAlgorithm() const=0;
60
61         /**
62          * Returns the size of the key.
63          *
64          * @return  the key size, or 0 if indeterminate
65          */
66         virtual unsigned int getKeySize() const=0;
67
68         /**
69          * Returns a secret or private key to use for signing or decryption operations.
70          * 
71          * @return  a secret or private key
72          */
73         virtual XSECCryptoKey* getPrivateKey() const=0;
74
75         /**
76          * Returns a secret or public key to use for verification or encryption operations.
77          * 
78          * @return  a secret or public key
79          */
80         virtual XSECCryptoKey* getPublicKey() const=0;
81         
82         /**
83          * Returns names representing the Credential, generally when the Credential itself merely
84          * points to a Credential rather than containing one.
85          * 
86          * @param results   array to populate with names
87          * @return  the number of names returned
88          */
89         virtual std::vector<std::string>::size_type getKeyNames(std::vector<std::string>& results) const=0;
90         
91         /**
92          * Returns a ds:KeyInfo object representing the Credential for use in
93          * communicating with other entities.
94          * 
95          * @param compact   true iff the communication medium is such that only compact forms should be included
96          * @return reference to a KeyInfo object
97          */
98         virtual const xmlsignature::KeyInfo* getKeyInfo(bool compact=false) const=0;
99
100         /**
101          * Compares the public key inside the Credential to a second public key.
102          *
103          * @param key   the public key to compare
104          * @return true iff the keys are equal
105          */
106         virtual bool isEqual(XSECCryptoKey& key) const;
107     };
108 };
109
110 #endif /* __xmltooling_cred_h__ */