From 9016e029ebf6af8030fe3d42a4cee2c32f39ee44 Mon Sep 17 00:00:00 2001 From: Scott Cantor Date: Sun, 13 Aug 2006 03:16:48 +0000 Subject: [PATCH] Expose key resolver caching. --- xmltooling/Makefile.am | 1 + xmltooling/signature/CachingKeyResolver.h | 45 +++++++++++++++++++++++++ xmltooling/signature/impl/InlineKeyResolver.cpp | 14 ++++++-- xmltooling/xmltooling.vcproj | 4 +++ 4 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 xmltooling/signature/CachingKeyResolver.h diff --git a/xmltooling/Makefile.am b/xmltooling/Makefile.am index bd5c2d4..cf26b0a 100644 --- a/xmltooling/Makefile.am +++ b/xmltooling/Makefile.am @@ -55,6 +55,7 @@ ioinclude_HEADERS = \ io/AbstractXMLObjectUnmarshaller.h siginclude_HEADERS = \ + signature/CachingKeyResolver.h \ signature/ContentReference.h \ signature/CredentialResolver.h \ signature/KeyInfo.h \ diff --git a/xmltooling/signature/CachingKeyResolver.h b/xmltooling/signature/CachingKeyResolver.h new file mode 100644 index 0000000..361a397 --- /dev/null +++ b/xmltooling/signature/CachingKeyResolver.h @@ -0,0 +1,45 @@ +/* + * Copyright 2001-2006 Internet2 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file xmltooling/signature/CachingKeyResolver.h + * + * A KeyResolver that caches content across method calls. + */ + +#if !defined(__xmltooling_cachekeyres_h__) && !defined(XMLTOOLING_NO_XMLSEC) +#define __xmltooling_cachekeyres_h__ + +#include + +namespace xmlsignature { + + /** + * An API for resolving encrypted decryption keys. + */ + class XMLTOOL_API CachingKeyResolver : public xmlsignature::KeyResolver { + public: + virtual ~CachingKeyResolver() {} + + /** + * Clears any cache state. + */ + virtual void clearCache()=0; + }; + +}; + +#endif /* __xmltooling_cachekeyres_h__ */ diff --git a/xmltooling/signature/impl/InlineKeyResolver.cpp b/xmltooling/signature/impl/InlineKeyResolver.cpp index c34db20..8a4ffcf 100644 --- a/xmltooling/signature/impl/InlineKeyResolver.cpp +++ b/xmltooling/signature/impl/InlineKeyResolver.cpp @@ -21,7 +21,7 @@ */ #include "internal.h" -#include "signature/KeyResolver.h" +#include "signature/CachingKeyResolver.h" #include "util/NDC.h" #include "util/Threads.h" @@ -42,7 +42,7 @@ using namespace log4cpp; using namespace std; namespace xmlsignature { - class XMLTOOL_DLLLOCAL InlineKeyResolver : public KeyResolver + class XMLTOOL_DLLLOCAL InlineKeyResolver : public CachingKeyResolver { public: InlineKeyResolver(const DOMElement* e); @@ -53,6 +53,14 @@ namespace xmlsignature { vector::size_type resolveCertificates(const KeyInfo* keyInfo, vector& certs) const; vector::size_type resolveCertificates(DSIGKeyInfoList* keyInfo, vector& certs) const; + void clearCache() { + if (m_lock) + m_lock->wrlock(); + m_cache.clear(); + if (m_lock) + m_lock->unlock(); + } + private: struct XMLTOOL_DLLLOCAL CacheEntry { CacheEntry() : m_key(NULL) {} @@ -89,7 +97,7 @@ InlineKeyResolver::InlineKeyResolver(const DOMElement* e) : m_lock(NULL) InlineKeyResolver::~InlineKeyResolver() { - m_cache.clear(); + clearCache(); delete m_lock; } diff --git a/xmltooling/xmltooling.vcproj b/xmltooling/xmltooling.vcproj index 9f6a1ff..9860bce 100644 --- a/xmltooling/xmltooling.vcproj +++ b/xmltooling/xmltooling.vcproj @@ -519,6 +519,10 @@ Name="signature" > + + -- 2.1.4