Major revamp of credential and trust handling code, PKIX engine still needs work.
[shibboleth/cpp-xmltooling.git] / xmltooling / encryption / impl / EncryptedKeyResolver.cpp
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 /**
18  * EncryptedKeyResolver.cpp
19  * 
20  * Resolves encrypted keys based on EncryptedData information or other external factors.
21  */
22
23 #include "internal.h"
24 #include "encryption/EncryptedKeyResolver.h"
25
26 using namespace xmlencryption;
27 using namespace xmlsignature;
28 using namespace xmltooling;
29 using namespace std;
30
31 const EncryptedKey* EncryptedKeyResolver::resolveKey(const EncryptedData& encryptedData, const XMLCh* recipient) const
32 {
33     if (!encryptedData.getKeyInfo())
34         return NULL;
35
36     const vector<XMLObject*>& others=const_cast<const KeyInfo*>(encryptedData.getKeyInfo())->getUnknownXMLObjects();
37     for (vector<XMLObject*>::const_iterator i=others.begin(); i!=others.end(); i++) {
38         EncryptedKey* encKey=dynamic_cast<EncryptedKey*>(*i);
39         if (encKey && (!recipient || !encKey->getRecipient() || XMLString::equals(recipient,encKey->getRecipient())))
40             return encKey;
41     }
42
43     return NULL;
44 }