2 * Copyright 2001-2010 Internet2
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * EncryptedKeyResolver.cpp
20 * Resolves encrypted keys based on EncryptedData information or other external factors.
24 #include "encryption/EncryptedKeyResolver.h"
25 #include "signature/KeyInfo.h"
27 using namespace xmlencryption;
28 using namespace xmlsignature;
29 using namespace xmltooling;
32 EncryptedKeyResolver::EncryptedKeyResolver()
36 EncryptedKeyResolver::~EncryptedKeyResolver()
40 const EncryptedKey* EncryptedKeyResolver::resolveKey(const EncryptedData& encryptedData, const XMLCh* recipient) const
42 if (!encryptedData.getKeyInfo())
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())))