2.0 SOAP Encoder
[shibboleth/cpp-opensaml.git] / saml / security / MetadataKeyInfoIterator.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  * MetadataKeyInfoIterator.h
19  * 
20  * Adapter between SAML metadata and TrustEngine KeyInfoIterator interface.
21  */
22
23 #ifndef __saml_keyiter_h__
24 #define __saml_keyiter_h__
25
26 #include <saml/saml2/metadata/Metadata.h>
27
28 #include <xmltooling/security/TrustEngine.h>
29
30 namespace opensaml {
31     
32     /**
33      * Adapter between SAML metadata and TrustEngine KeyInfoIterator interface. 
34      */
35     class SAML_API MetadataKeyInfoIterator : public xmltooling::TrustEngine::KeyInfoIterator
36     {
37         const std::vector<saml2md::KeyDescriptor*>& m_keys;
38         std::vector<saml2md::KeyDescriptor*>::const_iterator m_iter;
39         
40         void advance() {
41             while (hasNext()) {
42                 const XMLCh* use=(*m_iter)->getUse();
43                 if ((!use || !*use || XMLString::equals(use,saml2md::KeyDescriptor::KEYTYPE_SIGNING)) && (*m_iter)->getKeyInfo())
44                     return;
45                 m_iter++;
46             }
47         }
48         
49     public:
50         MetadataKeyInfoIterator(const saml2md::RoleDescriptor& role) : m_keys(role.getKeyDescriptors()) {
51             m_iter=m_keys.begin();
52             advance();
53         }
54
55         virtual ~MetadataKeyInfoIterator() {}
56         
57         /**
58          * Indicates whether additional KeyInfo objects are available.
59          * 
60          * @return true iff another KeyInfo object can be fetched
61          */
62         virtual bool hasNext() const {
63             return m_iter!=m_keys.end();
64         }
65         
66         /**
67          * Returns the next KeyInfo object available.
68          * 
69          * @return the next KeyInfo object, or NULL if none are left
70          */
71         virtual const xmlsignature::KeyInfo* next() {
72             xmlsignature::KeyInfo* ret = (*m_iter)->getKeyInfo();
73             m_iter++;
74             advance();
75             return ret;
76         }
77     };
78 };
79
80 #endif /* __saml_keyiter_h__ */