summaryrefslogtreecommitdiffstats
path: root/xmlsecurity
diff options
context:
space:
mode:
authorArkadiy Illarionov <qarkai@gmail.com>2019-05-09 15:17:26 +0300
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-05-09 18:21:59 +0200
commitfac093e5e63bd53bae3de552fedba927bd5c4561 (patch)
tree7b921dc813a6d6e0df55ef6d15edabb76e52bd40 /xmlsecurity
parentadd a way to specify SfxRequest preferred dialog parent (diff)
downloadcore-fac093e5e63bd53bae3de552fedba927bd5c4561.tar.gz
core-fac093e5e63bd53bae3de552fedba927bd5c4561.zip
Simplify Sequence iterations in xmlscript, xmlsecurity
Use range-based loops or replace with comphelper or STL functions Change-Id: I3d63811caf80c87a9d560087e1f0d933ebcc0d55 Reviewed-on: https://gerrit.libreoffice.org/72040 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmlsecurity')
-rw-r--r--xmlsecurity/source/component/documentdigitalsignatures.cxx19
-rw-r--r--xmlsecurity/source/dialogs/certificatechooser.cxx16
-rw-r--r--xmlsecurity/source/dialogs/macrosecurity.cxx5
-rw-r--r--xmlsecurity/source/framework/xmlsignaturetemplateimpl.cxx8
-rw-r--r--xmlsecurity/source/helper/documentsignaturehelper.cxx30
-rw-r--r--xmlsecurity/source/helper/documentsignaturemanager.cxx7
-rw-r--r--xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx13
-rw-r--r--xmlsecurity/source/xmlsec/saxhelper.cxx7
8 files changed, 40 insertions, 65 deletions
diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx b/xmlsecurity/source/component/documentdigitalsignatures.cxx
index 5e2f2d5ee056..834f6dc0a462 100644
--- a/xmlsecurity/source/component/documentdigitalsignatures.cxx
+++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx
@@ -619,24 +619,15 @@ void DocumentDigitalSignatures::showCertificate(
sal_Bool DocumentDigitalSignatures::isAuthorTrusted(
const Reference< css::security::XCertificate >& Author )
{
- bool bFound = false;
-
OUString sSerialNum = xmlsecurity::bigIntegerToNumericString( Author->getSerialNumber() );
Sequence< SvtSecurityOptions::Certificate > aTrustedAuthors = SvtSecurityOptions().GetTrustedAuthors();
- const SvtSecurityOptions::Certificate* pAuthors = aTrustedAuthors.getConstArray();
- const SvtSecurityOptions::Certificate* pAuthorsEnd = pAuthors + aTrustedAuthors.getLength();
- for ( ; pAuthors != pAuthorsEnd; ++pAuthors )
- {
- SvtSecurityOptions::Certificate aAuthor = *pAuthors;
- if ( ( aAuthor[0] == Author->getIssuerName() ) && ( aAuthor[1] == sSerialNum ) )
- {
- bFound = true;
- break;
- }
- }
- return bFound;
+ return std::any_of(aTrustedAuthors.begin(), aTrustedAuthors.end(),
+ [&Author, &sSerialNum](const SvtSecurityOptions::Certificate& rAuthor) {
+ return ( rAuthor[0] == Author->getIssuerName() )
+ && ( rAuthor[1] == sSerialNum );
+ });
}
uno::Sequence<Reference<css::security::XCertificate>>
diff --git a/xmlsecurity/source/dialogs/certificatechooser.cxx b/xmlsecurity/source/dialogs/certificatechooser.cxx
index bb6905acedb8..68bd9efbb497 100644
--- a/xmlsecurity/source/dialogs/certificatechooser.cxx
+++ b/xmlsecurity/source/dialogs/certificatechooser.cxx
@@ -198,23 +198,23 @@ void CertificateChooser::ImplInitialize()
// fill list of certificates; the first entry will be selected
- for ( sal_Int32 nC = 0; nC < nCertificates; ++nC )
+ for ( const auto& xCert : xCerts )
{
std::shared_ptr<UserData> userData = std::make_shared<UserData>();
- userData->xCertificate = xCerts[ nC ];
+ userData->xCertificate = xCert;
userData->xSecurityContext = secContext;
userData->xSecurityEnvironment = secEnvironment;
mvUserData.push_back(userData);
- OUString sIssuer = xmlsec::GetContentPart( xCerts[ nC ]->getIssuerName() );
+ OUString sIssuer = xmlsec::GetContentPart( xCert->getIssuerName() );
m_xCertLB->append();
int nRow = m_xCertLB->n_children() - 1;
- m_xCertLB->set_text(nRow, xmlsec::GetContentPart(xCerts[nC]->getSubjectName()), 0);
+ m_xCertLB->set_text(nRow, xmlsec::GetContentPart(xCert->getSubjectName()), 0);
m_xCertLB->set_text(nRow, sIssuer, 1);
- m_xCertLB->set_text(nRow, xmlsec::GetCertificateKind(xCerts[nC]->getCertificateKind()), 2);
- m_xCertLB->set_text(nRow, utl::GetDateString(xCerts[nC]->getNotValidAfter()), 3);
- m_xCertLB->set_text(nRow, UsageInClearText(xCerts[nC]->getCertificateUsage()), 4);
+ m_xCertLB->set_text(nRow, xmlsec::GetCertificateKind(xCert->getCertificateKind()), 2);
+ m_xCertLB->set_text(nRow, utl::GetDateString(xCert->getNotValidAfter()), 3);
+ m_xCertLB->set_text(nRow, UsageInClearText(xCert->getCertificateUsage()), 4);
OUString sId(OUString::number(reinterpret_cast<sal_Int64>(userData.get())));
m_xCertLB->set_id(nRow, sId);
@@ -226,7 +226,7 @@ void CertificateChooser::ImplInitialize()
m_xCertLB->select(nRow);
else if ( meAction == UserAction::Encrypt &&
aUserOpts.GetEncryptToSelf() )
- mxEncryptToSelf = xCerts[nC];
+ mxEncryptToSelf = xCert;
}
#endif
}
diff --git a/xmlsecurity/source/dialogs/macrosecurity.cxx b/xmlsecurity/source/dialogs/macrosecurity.cxx
index 59e62442909f..206781851b78 100644
--- a/xmlsecurity/source/dialogs/macrosecurity.cxx
+++ b/xmlsecurity/source/dialogs/macrosecurity.cxx
@@ -363,10 +363,9 @@ MacroSecurityTrustedSourcesTP::MacroSecurityTrustedSourcesTP(weld::Container* pP
m_xTrustFileLocLB->set_sensitive(!mbURLsReadonly);
m_xAddLocPB->set_sensitive(!mbURLsReadonly);
- sal_Int32 nEntryCnt = aSecureURLs.getLength();
- for (sal_Int32 i = 0; i < nEntryCnt; ++i)
+ for (const auto& rSecureURL : aSecureURLs)
{
- OUString aSystemFileURL( aSecureURLs[ i ] );
+ OUString aSystemFileURL( rSecureURL );
osl::FileBase::getSystemPathFromFileURL( aSystemFileURL, aSystemFileURL );
m_xTrustFileLocLB->append_text(aSystemFileURL);
}
diff --git a/xmlsecurity/source/framework/xmlsignaturetemplateimpl.cxx b/xmlsecurity/source/framework/xmlsignaturetemplateimpl.cxx
index c83c7751e794..869f1bf26371 100644
--- a/xmlsecurity/source/framework/xmlsignaturetemplateimpl.cxx
+++ b/xmlsecurity/source/framework/xmlsignaturetemplateimpl.cxx
@@ -20,6 +20,7 @@
#include <sal/config.h>
#include <rtl/ustring.hxx>
#include <framework/xmlsignaturetemplateimpl.hxx>
+#include <comphelper/sequence.hxx>
using namespace ::com::sun::star::uno ;
using ::com::sun::star::lang::XMultiServiceFactory ;
@@ -97,12 +98,7 @@ OUString SAL_CALL XMLSignatureTemplateImpl::getImplementationName() {
/* XServiceInfo */
sal_Bool SAL_CALL XMLSignatureTemplateImpl::supportsService( const OUString& serviceName) {
Sequence< OUString > seqServiceNames = getSupportedServiceNames() ;
- const OUString* pArray = seqServiceNames.getConstArray() ;
- for( sal_Int32 i = 0 ; i < seqServiceNames.getLength() ; i ++ ) {
- if( *( pArray + i ) == serviceName )
- return true ;
- }
- return false ;
+ return comphelper::findValue(seqServiceNames, serviceName) != -1;
}
/* XServiceInfo */
diff --git a/xmlsecurity/source/helper/documentsignaturehelper.cxx b/xmlsecurity/source/helper/documentsignaturehelper.cxx
index f1929f927758..66a058c1d3dd 100644
--- a/xmlsecurity/source/helper/documentsignaturehelper.cxx
+++ b/xmlsecurity/source/helper/documentsignaturehelper.cxx
@@ -87,42 +87,40 @@ static void ImplFillElementList(
{
Reference < css::container::XNameAccess > xElements( rxStore, UNO_QUERY );
Sequence< OUString > aElements = xElements->getElementNames();
- sal_Int32 nElements = aElements.getLength();
- const OUString* pNames = aElements.getConstArray();
- for ( sal_Int32 n = 0; n < nElements; n++ )
+ for ( const auto& rName : aElements )
{
- if (pNames[n] == "[Content_Types].xml")
+ if (rName == "[Content_Types].xml")
// OOXML
continue;
// If the user enabled validating according to OOo 3.0
// then mimetype and all content of META-INF must be excluded.
if (mode != DocumentSignatureAlgorithm::OOo3_2
- && (pNames[n] == "META-INF" || pNames[n] == "mimetype"))
+ && (rName == "META-INF" || rName == "mimetype"))
{
continue;
}
else
{
OUString sEncName = ::rtl::Uri::encode(
- pNames[n], rtl_UriCharClassRelSegment,
+ rName, rtl_UriCharClassRelSegment,
rtl_UriEncodeStrict, RTL_TEXTENCODING_UTF8);
- if (sEncName.isEmpty() && !pNames[n].isEmpty())
+ if (sEncName.isEmpty() && !rName.isEmpty())
throw css::uno::RuntimeException("Failed to encode element name of XStorage", nullptr);
- if ( rxStore->isStreamElement( pNames[n] ) )
+ if ( rxStore->isStreamElement( rName ) )
{
//Exclude documentsignatures.xml!
- if (pNames[n] ==
+ if (rName ==
DocumentSignatureHelper::GetDocumentContentSignatureDefaultStreamName())
continue;
OUString aFullName( rRootStorageName + sEncName );
rList.push_back(aFullName);
}
- else if ( bRecursive && rxStore->isStorageElement( pNames[n] ) )
+ else if ( bRecursive && rxStore->isStorageElement( rName ) )
{
- Reference < css::embed::XStorage > xSubStore = rxStore->openStorageElement( pNames[n], css::embed::ElementModes::READ );
+ Reference < css::embed::XStorage > xSubStore = rxStore->openStorageElement( rName, css::embed::ElementModes::READ );
OUString aFullRootName( rRootStorageName + sEncName + "/" );
ImplFillElementList(rList, xSubStore, aFullRootName, bRecursive, mode);
}
@@ -217,14 +215,12 @@ DocumentSignatureHelper::CreateElementList(
// Object folders...
Reference < css::container::XNameAccess > xElements( rxStore, UNO_QUERY );
Sequence< OUString > aElementNames = xElements->getElementNames();
- sal_Int32 nElements = aElementNames.getLength();
- const OUString* pNames = aElementNames.getConstArray();
- for ( sal_Int32 n = 0; n < nElements; n++ )
+ for ( const auto& rName : aElementNames )
{
- if ( ( pNames[n].match( "Object " ) ) && rxStore->isStorageElement( pNames[n] ) )
+ if ( ( rName.match( "Object " ) ) && rxStore->isStorageElement( rName ) )
{
- Reference < css::embed::XStorage > xTmpSubStore = rxStore->openStorageElement( pNames[n], css::embed::ElementModes::READ );
- ImplFillElementList(aElements, xTmpSubStore, pNames[n]+aSep, true, mode);
+ Reference < css::embed::XStorage > xTmpSubStore = rxStore->openStorageElement( rName, css::embed::ElementModes::READ );
+ ImplFillElementList(aElements, xTmpSubStore, rName+aSep, true, mode);
}
}
}
diff --git a/xmlsecurity/source/helper/documentsignaturemanager.cxx b/xmlsecurity/source/helper/documentsignaturemanager.cxx
index 9cd197e786ae..305a98fb884d 100644
--- a/xmlsecurity/source/helper/documentsignaturemanager.cxx
+++ b/xmlsecurity/source/helper/documentsignaturemanager.cxx
@@ -181,15 +181,12 @@ bool DocumentSignatureManager::isXML(const OUString& rURI)
if (readManifest())
{
- for (int i = 0; i < m_manifest.getLength(); i++)
+ for (const uno::Sequence<beans::PropertyValue>& entry : m_manifest)
{
- const uno::Sequence<beans::PropertyValue>& entry = m_manifest[i];
OUString sPath, sMediaType;
bool bEncrypted = false;
- for (int j = 0; j < entry.getLength(); j++)
+ for (const beans::PropertyValue& prop : entry)
{
- const beans::PropertyValue& prop = entry[j];
-
if (prop.Name == sPropFullPath)
prop.Value >>= sPath;
else if (prop.Name == sPropMediaType)
diff --git a/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx
index d67bf2e517e4..a5015bc87c55 100644
--- a/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx
+++ b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx
@@ -142,12 +142,7 @@ OUString SAL_CALL SecurityEnvironment_NssImpl::getImplementationName() {
/* XServiceInfo */
sal_Bool SAL_CALL SecurityEnvironment_NssImpl::supportsService( const OUString& serviceName) {
Sequence< OUString > seqServiceNames = getSupportedServiceNames() ;
- const OUString* pArray = seqServiceNames.getConstArray() ;
- for( sal_Int32 i = 0 ; i < seqServiceNames.getLength() ; i ++ ) {
- if( *( pArray + i ) == serviceName )
- return true ;
- }
- return false ;
+ return comphelper::findValue(seqServiceNames, serviceName) != -1;
}
/* XServiceInfo */
@@ -545,9 +540,9 @@ verifyCertificate( const Reference< csss::XCertificate >& aCert,
{
//prepare the intermediate certificates
- for (sal_Int32 i = 0; i < intermediateCerts.getLength(); i++)
+ for (const auto& rIntermediateCert : intermediateCerts)
{
- Sequence<sal_Int8> der = intermediateCerts[i]->getEncoded();
+ Sequence<sal_Int8> der = rIntermediateCert->getEncoded();
SECItem item;
item.type = siBuffer;
item.data = reinterpret_cast<unsigned char*>(der.getArray());
@@ -559,7 +554,7 @@ verifyCertificate( const Reference< csss::XCertificate >& aCert,
PR_TRUE /* copyDER */);
if (!certTmp)
{
- SAL_INFO("xmlsecurity.xmlsec", "Failed to add a temporary certificate: " << intermediateCerts[i]->getIssuerName());
+ SAL_INFO("xmlsecurity.xmlsec", "Failed to add a temporary certificate: " << rIntermediateCert->getIssuerName());
}
else
diff --git a/xmlsecurity/source/xmlsec/saxhelper.cxx b/xmlsecurity/source/xmlsec/saxhelper.cxx
index bf3c39127c44..d9e71226a7b8 100644
--- a/xmlsecurity/source/xmlsec/saxhelper.cxx
+++ b/xmlsecurity/source/xmlsec/saxhelper.cxx
@@ -76,10 +76,11 @@ static const xmlChar** attrlist_to_nxmlstr( const cssu::Sequence< cssxcsax::XMLA
return nullptr ;
}
- for( int i = 0 , j = 0 ; j < nLength ; ++j )
+ int i = 0;
+ for( const auto& rAttr : aAttributes )
{
- attname = ous_to_xmlstr( aAttributes[j].sName ) ;
- attvalue = ous_to_xmlstr( aAttributes[j].sValue ) ;
+ attname = ous_to_xmlstr( rAttr.sName ) ;
+ attvalue = ous_to_xmlstr( rAttr.sValue ) ;
if( attname != nullptr && attvalue != nullptr )
{