Update copyright.
[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/signature/KeyResolver.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 Key or a KeyResolver
34      */
35     class XMLTOOL_API SignatureValidator : public xmltooling::Validator
36     {
37     public:
38         /**
39          * Constructor using a KeyResolver
40          * 
41          * @param resolver the key resolver to use, will be freed by Validator
42          */
43         SignatureValidator(KeyResolver* resolver) : m_key(NULL), m_resolver(resolver) {
44         }
45
46         /**
47          * Constructor using a Key
48          * 
49          * @param key the verification key to use, will be freed by Validator
50          */
51         SignatureValidator(XSECCryptoKey* key=NULL) : m_key(key), m_resolver(NULL) {
52         }
53         
54         virtual ~SignatureValidator() {
55             delete m_key;
56             delete m_resolver;
57         }
58
59         virtual void validate(const xmltooling::XMLObject* xmlObject) const;
60
61         /**
62          * Type-safe validator.
63          * 
64          * @param signature object to validate
65          */
66         virtual void validate(const Signature* signature) const;
67         
68         /**
69          * Replace the current Key, if any, with a new one.
70          * 
71          * @param key  the Key to attach 
72          */
73         void setKey(XSECCryptoKey* key) {
74             delete m_key;
75             delete m_resolver;
76             m_resolver=NULL;
77             m_key=key;
78         }
79
80         /**
81          * Replace the current KeyResolver, if any, with a new one.
82          * 
83          * @param resolver  the KeyResolver to attach 
84          */
85         void setKeyResolver(KeyResolver* resolver) {
86             delete m_key;
87             delete m_resolver;
88             m_key=NULL;
89             m_resolver=resolver;
90         }
91     
92     protected:
93         /** Verification key. */
94         XSECCryptoKey* m_key;
95         
96         /** KeyResolver to use against signature. */
97         KeyResolver* m_resolver;
98     };
99
100 };
101
102 #endif /* __xmltooling_sigval_h__ */