Major revamp of credential and trust handling code, PKIX engine still needs work.
[shibboleth/cpp-xmltooling.git] / xmltooling / signature / SignatureValidator.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 SignatureValidator.h
19  * 
20  * Validator for signatures based on an externally-supplied key 
21  */
22
23 #if !defined(__xmltooling_sigval_h__) && !defined(XMLTOOLING_NO_XMLSEC)
24 #define __xmltooling_sigval_h__
25
26 #include <xmltooling/security/Credential.h>
27 #include <xmltooling/signature/Signature.h>
28 #include <xmltooling/validation/Validator.h>
29
30 namespace xmlsignature {
31
32     /**
33      * Validator for signatures based on a Credential
34      */
35     class XMLTOOL_API SignatureValidator : public xmltooling::Validator
36     {
37     public:
38         /**
39          * Constructor using a key
40          * 
41          * @param key the key to use
42          */
43         SignatureValidator(XSECCryptoKey* key=NULL) : m_key(key), m_credential(NULL) {}
44
45         /**
46          * Constructor using a Credential
47          * 
48          * @param credential the credential to use
49          */
50         SignatureValidator(const xmltooling::Credential* credential) : m_key(NULL), m_credential(credential) {}
51
52         virtual ~SignatureValidator() {}
53
54         virtual void validate(const xmltooling::XMLObject* xmlObject) const;
55
56         /**
57          * Type-safe validator.
58          * 
59          * @param signature object to validate
60          */
61         virtual void validate(const Signature* signature) const;
62         
63         /**
64          * Replace the current key, if any, with a new one.
65          * 
66          * @param key  the key to attach 
67          */
68         void setKey(XSECCryptoKey* key) {
69             m_key = key;
70             m_credential = NULL;
71         }
72
73         /**
74          * Replace the current Credential, if any, with a new one.
75          * 
76          * @param credential  the Credential to attach 
77          */
78         void setCredential(const xmltooling::Credential* credential) {
79             m_key = NULL;
80             m_credential = credential;
81         }
82     
83     protected:
84         /** Verification key. */
85         XSECCryptoKey* m_key;
86
87         /** Verification credential. */
88         const xmltooling::Credential* m_credential;
89     };
90
91 };
92
93 #endif /* __xmltooling_sigval_h__ */