2d40dab209a29ebb1a549eaac221f863f7675f28
[shibboleth/cpp-opensaml.git] / samltest / signature / SAMLSignatureTestBase.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 #include "internal.h"
18 #include <saml/signature/SignatureProfileValidator.h>
19
20 #include <xmltooling/security/CredentialResolver.h>
21 #include <xmltooling/signature/KeyInfo.h>
22 #include <xmltooling/signature/SignatureValidator.h>
23
24 using namespace xmlsignature;
25
26 class _addcert : public std::binary_function<X509Data*,XSECCryptoX509*,void> {
27 public:
28     void operator()(X509Data* bag, XSECCryptoX509* cert) const {
29         safeBuffer& buf=cert->getDEREncodingSB();
30         X509Certificate* x=X509CertificateBuilder::buildX509Certificate();
31         x->setValue(buf.sbStrToXMLCh());
32         bag->getX509Certificates().push_back(x);
33     }
34 };
35
36 class SAMLSignatureTestBase : public SAMLObjectBaseTestCase {
37 protected:
38     CredentialResolver* m_resolver;
39 public:
40     void setUp() {
41         m_resolver=NULL;
42         SAMLObjectBaseTestCase::setUp();
43         string config = data_path + "FilesystemCredentialResolver.xml";
44         ifstream in(config.c_str());
45         DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
46         XercesJanitor<DOMDocument> janitor(doc);
47         m_resolver = XMLToolingConfig::getConfig().CredentialResolverManager.newPlugin(
48             FILESYSTEM_CREDENTIAL_RESOLVER,doc->getDocumentElement()
49             );
50     }
51
52     void tearDown() {
53         delete m_resolver;
54         SAMLObjectBaseTestCase::tearDown();
55     }
56 };