SAML TrustEngine wrappers, ExplicitKeyTrustEngine plugin.
[shibboleth/cpp-opensaml.git] / saml / security / MetadataKeyInfoIterator.h
1 /*\r
2  *  Copyright 2001-2006 Internet2\r
3  * \r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 /**\r
18  * MetadataKeyInfoIterator.h\r
19  * \r
20  * Adapter between SAML metadata and TrustEngine KeyInfoIterator interface.\r
21  */\r
22 \r
23 #ifndef __saml_keyiter_h__\r
24 #define __saml_keyiter_h__\r
25 \r
26 #include <saml/saml2/metadata/Metadata.h>\r
27 \r
28 #include <xmltooling/security/TrustEngine.h>\r
29 \r
30 namespace opensaml {\r
31     \r
32     /**\r
33      * Adapter between SAML metadata and TrustEngine KeyInfoIterator interface. \r
34      */\r
35     class SAML_API MetadataKeyInfoIterator : public xmltooling::TrustEngine::KeyInfoIterator\r
36     {\r
37         const std::vector<saml2md::KeyDescriptor*>& m_keys;\r
38         std::vector<saml2md::KeyDescriptor*>::const_iterator m_iter;\r
39         \r
40         void advance() {\r
41             while (hasNext()) {\r
42                 const XMLCh* use=(*m_iter)->getUse();\r
43                 if ((!use || !*use || XMLString::equals(use,saml2md::KeyDescriptor::KEYTYPE_SIGNING)) && (*m_iter)->getKeyInfo())\r
44                     return;\r
45                 m_iter++;\r
46             }\r
47         }\r
48         \r
49     public:\r
50         MetadataKeyInfoIterator(const saml2md::RoleDescriptor& role) : m_keys(role.getKeyDescriptors()) {\r
51             m_iter=m_keys.begin();\r
52             advance();\r
53         }\r
54 \r
55         virtual ~MetadataKeyInfoIterator() {}\r
56         \r
57         /**\r
58          * Indicates whether additional KeyInfo objects are available.\r
59          * \r
60          * @return true iff another KeyInfo object can be fetched\r
61          */\r
62         virtual bool hasNext() const {\r
63             return m_iter!=m_keys.end();\r
64         }\r
65         \r
66         /**\r
67          * Returns the next KeyInfo object available.\r
68          * \r
69          * @return the next KeyInfo object, or NULL if none are left\r
70          */\r
71         virtual const xmlsignature::KeyInfo* next() {\r
72             xmlsignature::KeyInfo* ret = (*m_iter)->getKeyInfo();\r
73             m_iter++;\r
74             advance();\r
75             return ret;\r
76         }\r
77     };\r
78 };\r
79 \r
80 #endif /* __saml_keyiter_h__ */\r