gcc const fix, converted linefeeds
[shibboleth/cpp-xmltooling.git] / xmltooling / signature / SignatureValidator.h
1 /*
2  *  Copyright 2001-2006 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         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             delete m_key;
70             delete m_resolver;
71             m_resolver=NULL;
72             m_key=key;
73         }
74
75         /**
76          * Replace the current KeyResolver, if any, with a new one.
77          * 
78          * @param resolver  the KeyResolver to attach 
79          */
80         void setKeyResolver(KeyResolver* resolver) {
81             delete m_key;
82             delete m_resolver;
83             m_key=NULL;
84             m_resolver=resolver;
85         }
86     
87     protected:
88         XSECCryptoKey* m_key;
89         KeyResolver* m_resolver;
90     };
91
92 };
93
94 #endif /* __xmltooling_sigval_h__ */