+ class SAML_DLLLOCAL EncryptedElementTypeImpl : public virtual EncryptedElementType,
+ public AbstractComplexElement,
+ public AbstractDOMCachingXMLObject,
+ public AbstractValidatingXMLObject,
+ public AbstractXMLObjectMarshaller,
+ public AbstractXMLObjectUnmarshaller
+ {
+ void init() {
+ m_EncryptedData=NULL;
+ m_children.push_back(NULL);
+ m_pos_EncryptedData=m_children.begin();
+ }
+
+ protected:
+ EncryptedElementTypeImpl() {
+ init();
+ }
+
+ public:
+ virtual ~EncryptedElementTypeImpl() {}
+
+ EncryptedElementTypeImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
+ : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
+ init();
+ }
+
+ EncryptedElementTypeImpl(const EncryptedElementTypeImpl& src)
+ : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src), AbstractValidatingXMLObject(src) {
+ init();
+ if (src.getEncryptedData())
+ setEncryptedData(src.getEncryptedData()->cloneEncryptedData());
+ VectorOf(EncryptedKey) v=getEncryptedKeys();
+ for (vector<EncryptedKey*>::const_iterator i=src.m_EncryptedKeys.begin(); i!=src.m_EncryptedKeys.end(); i++) {
+ if (*i) {
+ v.push_back((*i)->cloneEncryptedKey());
+ }
+ }
+ }
+
+ XMLObject* decrypt(KeyResolver* KEKresolver, const XMLCh* recipient) const
+ {
+ if (!m_EncryptedData)
+ throw DecryptionException("No encrypted data present.");
+ Decrypter decrypter(KEKresolver, new EncryptedKeyResolver(*this, recipient));
+ DOMDocumentFragment* frag = decrypter.decryptData(m_EncryptedData);
+ if (frag->hasChildNodes() && frag->getFirstChild()==frag->getLastChild()) {
+ DOMNode* plaintext=frag->getFirstChild();
+ if (plaintext->getNodeType()==DOMNode::ELEMENT_NODE) {
+ auto_ptr<XMLObject> ret(XMLObjectBuilder::buildOneFromElement(static_cast<DOMElement*>(plaintext)));
+ ret->releaseThisAndChildrenDOM();
+ return ret.release();
+ }
+ }
+ frag->release();
+ throw DecryptionException("Decryption did not result in a single element.");
+ }
+
+ IMPL_XMLOBJECT_CLONE(EncryptedElementType);
+ IMPL_TYPED_FOREIGN_CHILD(EncryptedData,xmlencryption);
+ IMPL_TYPED_FOREIGN_CHILDREN(EncryptedKey,xmlencryption,m_children.end());
+
+ protected:
+ void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
+ PROC_TYPED_FOREIGN_CHILD(EncryptedData,xmlencryption,XMLConstants::XMLENC_NS,false);
+ PROC_TYPED_FOREIGN_CHILDREN(EncryptedKey,xmlencryption,XMLConstants::XMLENC_NS,false);
+ AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
+ }
+ };
+
+ class SAML_DLLLOCAL EncryptedIDImpl : public virtual EncryptedID, public EncryptedElementTypeImpl
+ {
+ public:
+ virtual ~EncryptedIDImpl() {}
+
+ EncryptedIDImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
+ : AbstractXMLObject(nsURI, localName, prefix, schemaType) {}
+
+ EncryptedIDImpl(const EncryptedIDImpl& src) : AbstractXMLObject(src), EncryptedElementTypeImpl(src) {}
+
+ IMPL_XMLOBJECT_CLONE(EncryptedID);
+ EncryptedElementType* cloneEncryptedElementType() const {
+ return new EncryptedIDImpl(*this);
+ }
+ };
+