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