Convert from NULL macro to nullptr.
[shibboleth/cpp-xmltooling.git] / xmltooling / encryption / impl / EncryptedKeyResolver.cpp
1 /*
2  *  Copyright 2001-2010 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 #include "signature/KeyInfo.h"
26
27 using namespace xmlencryption;
28 using namespace xmlsignature;
29 using namespace xmltooling;
30 using namespace std;
31
32 EncryptedKeyResolver::EncryptedKeyResolver()
33 {
34 }
35
36 EncryptedKeyResolver::~EncryptedKeyResolver()
37 {
38 }
39
40 const EncryptedKey* EncryptedKeyResolver::resolveKey(const EncryptedData& encryptedData, const XMLCh* recipient) const
41 {
42     if (!encryptedData.getKeyInfo())
43         return nullptr;
44
45     const vector<XMLObject*>& others=const_cast<const KeyInfo*>(encryptedData.getKeyInfo())->getUnknownXMLObjects();
46     for (vector<XMLObject*>::const_iterator i=others.begin(); i!=others.end(); i++) {
47         EncryptedKey* encKey=dynamic_cast<EncryptedKey*>(*i);
48         if (encKey && (!recipient || !encKey->getRecipient() || XMLString::equals(recipient,encKey->getRecipient())))
49             return encKey;
50     }
51
52     return nullptr;
53 }