summaryrefslogtreecommitdiff
path: root/xmlsecurity
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2022-09-28 16:12:18 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-09-29 09:10:50 +0200
commita08468c1a5255d3fb04cd8a0dc627acdea40426a (patch)
treea14a625108947e3f9b3be73772c80ac31ab3fd7a /xmlsecurity
parentc74d97f1218a3592226a4fae4d4c1941dabe4f7a (diff)
use more string_view in xmlsecurity
Change-Id: I245961d0116a7a72f8506cfc0b009990e35c6796 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140710 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmlsecurity')
-rw-r--r--xmlsecurity/inc/documentsignaturehelper.hxx6
-rw-r--r--xmlsecurity/inc/xmlsignaturehelper.hxx2
-rw-r--r--xmlsecurity/qa/unit/signing/signing.cxx22
-rw-r--r--xmlsecurity/source/helper/documentsignaturehelper.cxx26
-rw-r--r--xmlsecurity/source/helper/xmlsignaturehelper.cxx2
-rw-r--r--xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx12
6 files changed, 35 insertions, 35 deletions
diff --git a/xmlsecurity/inc/documentsignaturehelper.hxx b/xmlsecurity/inc/documentsignaturehelper.hxx
index b18ccf103e20..eb50b3761423 100644
--- a/xmlsecurity/inc/documentsignaturehelper.hxx
+++ b/xmlsecurity/inc/documentsignaturehelper.hxx
@@ -70,14 +70,14 @@ namespace DocumentSignatureHelper
DocumentSignatureMode eMode,
const DocumentSignatureAlgorithm mode);
- bool isODFPre_1_2(const OUString & sODFVersion);
+ bool isODFPre_1_2(std::u16string_view sODFVersion);
bool isOOo3_2_Signature(const SignatureInformation & sigInfo);
DocumentSignatureAlgorithm getDocumentAlgorithm(
- const OUString & sODFVersion, const SignatureInformation & sigInfo);
+ std::u16string_view sODFVersion, const SignatureInformation & sigInfo);
bool CanSignWithGPG(const css::uno::Reference < css::embed::XStorage >& rxStore,
- const OUString& sOdfVersion);
+ std::u16string_view sOdfVersion);
bool checkIfAllFilesAreSigned( const ::std::vector< OUString > & sElementList,
const SignatureInformation & sigInfo, const DocumentSignatureAlgorithm alg);
diff --git a/xmlsecurity/inc/xmlsignaturehelper.hxx b/xmlsecurity/inc/xmlsignaturehelper.hxx
index de7de9908205..d6e2b90eebac 100644
--- a/xmlsecurity/inc/xmlsignaturehelper.hxx
+++ b/xmlsecurity/inc/xmlsignaturehelper.hxx
@@ -83,7 +83,7 @@ public:
// Set the storage which should be used by the default UriBinding
// Must be set before StartMission().
//sODFVersion indicates the ODF version
- void SetStorage( const css::uno::Reference < css::embed::XStorage >& rxStorage, const OUString& sODFVersion );
+ void SetStorage( const css::uno::Reference < css::embed::XStorage >& rxStorage, std::u16string_view sODFVersion );
// Argument for the Link is a uno::Reference< xml::sax::XAttributeList >*
// Return 1 to verify, 0 to skip.
diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx
index 48fc42091e02..19dc3821288d 100644
--- a/xmlsecurity/qa/unit/signing/signing.cxx
+++ b/xmlsecurity/qa/unit/signing/signing.cxx
@@ -185,7 +185,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testDescription)
ZIP_STORAGE_FORMAT_STRING, aTempFile.GetURL(), embed::ElementModes::READWRITE);
CPPUNIT_ASSERT(xStorage.is());
aManager.setStore(xStorage);
- aManager.getSignatureHelper().SetStorage(xStorage, "1.2");
+ aManager.getSignatureHelper().SetStorage(xStorage, u"1.2");
// Then add a signature document.
uno::Reference<security::XCertificate> xCertificate
@@ -222,7 +222,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testECDSA)
ZIP_STORAGE_FORMAT_STRING, aTempFile.GetURL(), embed::ElementModes::READWRITE);
CPPUNIT_ASSERT(xStorage.is());
aManager.setStore(xStorage);
- aManager.getSignatureHelper().SetStorage(xStorage, "1.2");
+ aManager.getSignatureHelper().SetStorage(xStorage, u"1.2");
// Then add a signature.
uno::Reference<security::XCertificate> xCertificate
@@ -261,7 +261,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testECDSAOOXML)
ZIP_STORAGE_FORMAT_STRING, aTempFile.GetURL(), embed::ElementModes::READWRITE);
CPPUNIT_ASSERT(xStorage.is());
aManager.setStore(xStorage);
- aManager.getSignatureHelper().SetStorage(xStorage, "1.2");
+ aManager.getSignatureHelper().SetStorage(xStorage, u"1.2");
// Then add a document signature.
uno::Reference<security::XCertificate> xCertificate
@@ -347,7 +347,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testOOXMLDescription)
ZIP_STORAGE_FORMAT_STRING, aTempFile.GetURL(), embed::ElementModes::READWRITE);
CPPUNIT_ASSERT(xStorage.is());
aManager.setStore(xStorage);
- aManager.getSignatureHelper().SetStorage(xStorage, "1.2");
+ aManager.getSignatureHelper().SetStorage(xStorage, u"1.2");
// Then add a document signature.
uno::Reference<security::XCertificate> xCertificate
@@ -383,7 +383,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testOOXMLAppend)
embed::ElementModes::READWRITE);
CPPUNIT_ASSERT(xStorage.is());
aManager.setStore(xStorage);
- aManager.getSignatureHelper().SetStorage(xStorage, "1.2");
+ aManager.getSignatureHelper().SetStorage(xStorage, u"1.2");
aManager.read(/*bUseTempStream=*/false);
std::vector<SignatureInformation>& rInformations = aManager.getCurrentSignatureInformations();
CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(1), rInformations.size());
@@ -419,7 +419,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testOOXMLRemove)
embed::ElementModes::READWRITE);
CPPUNIT_ASSERT(xStorage.is());
aManager.setStore(xStorage);
- aManager.getSignatureHelper().SetStorage(xStorage, "1.2");
+ aManager.getSignatureHelper().SetStorage(xStorage, u"1.2");
aManager.read(/*bUseTempStream=*/false);
std::vector<SignatureInformation>& rInformations = aManager.getCurrentSignatureInformations();
CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(2), rInformations.size());
@@ -455,7 +455,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testOOXMLRemoveAll)
embed::ElementModes::READWRITE);
CPPUNIT_ASSERT(xStorage.is());
aManager.setStore(xStorage);
- aManager.getSignatureHelper().SetStorage(xStorage, "1.2");
+ aManager.getSignatureHelper().SetStorage(xStorage, u"1.2");
aManager.read(/*bUseTempStream=*/false);
std::vector<SignatureInformation>& rInformations = aManager.getCurrentSignatureInformations();
CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(1), rInformations.size());
@@ -952,7 +952,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testXAdESNotype)
ZIP_STORAGE_FORMAT_STRING, aTempFile.GetURL(), embed::ElementModes::READWRITE);
CPPUNIT_ASSERT(xStorage.is());
aManager.setStore(xStorage);
- aManager.getSignatureHelper().SetStorage(xStorage, "1.2");
+ aManager.getSignatureHelper().SetStorage(xStorage, u"1.2");
aManager.read(/*bUseTempStream=*/false);
// Create a new signature.
@@ -1013,7 +1013,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testXAdES)
ZIP_STORAGE_FORMAT_STRING, aTempFile.GetURL(), embed::ElementModes::READWRITE);
CPPUNIT_ASSERT(xStorage.is());
aManager.setStore(xStorage);
- aManager.getSignatureHelper().SetStorage(xStorage, "1.2");
+ aManager.getSignatureHelper().SetStorage(xStorage, u"1.2");
// Create a signature.
uno::Reference<security::XCertificate> xCertificate
@@ -1072,7 +1072,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testSigningMultipleTimes_ODT)
ZIP_STORAGE_FORMAT_STRING, aTempFile.GetURL(), embed::ElementModes::READWRITE);
CPPUNIT_ASSERT(xStorage.is());
aManager.setStore(xStorage);
- aManager.getSignatureHelper().SetStorage(xStorage, "1.2");
+ aManager.getSignatureHelper().SetStorage(xStorage, u"1.2");
// Create a signature.
uno::Reference<security::XCertificate> xCertificate
@@ -1151,7 +1151,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testSigningMultipleTimes_OOXML)
ZIP_STORAGE_FORMAT_STRING, aTempFile.GetURL(), embed::ElementModes::READWRITE);
CPPUNIT_ASSERT(xStorage.is());
aManager.setStore(xStorage);
- aManager.getSignatureHelper().SetStorage(xStorage, "1.2");
+ aManager.getSignatureHelper().SetStorage(xStorage, u"1.2");
// Create a signature.
uno::Reference<security::XCertificate> xCertificate
diff --git a/xmlsecurity/source/helper/documentsignaturehelper.cxx b/xmlsecurity/source/helper/documentsignaturehelper.cxx
index 2a9c8fd92d39..e1cf34ca5521 100644
--- a/xmlsecurity/source/helper/documentsignaturehelper.cxx
+++ b/xmlsecurity/source/helper/documentsignaturehelper.cxx
@@ -52,26 +52,26 @@ using namespace css::xml::sax;
namespace
{
-OUString getElement(OUString const & version, ::sal_Int32 * index)
+std::u16string_view getElement(std::u16string_view version, size_t * index)
{
- while (*index < version.getLength() && version[*index] == '0') {
+ while (*index < version.size() && version[*index] == '0') {
++*index;
}
- return version.getToken(0, '.', *index);
+ return o3tl::getToken(version, u'.', *index);
}
// Return 1 if version1 is greater than version 2, 0 if they are equal
//and -1 if version1 is less version 2
int compareVersions(
- OUString const & version1, OUString const & version2)
+ std::u16string_view version1, std::u16string_view version2)
{
- for (::sal_Int32 i1 = 0, i2 = 0; i1 >= 0 || i2 >= 0;) {
- OUString e1(getElement(version1, &i1));
- OUString e2(getElement(version2, &i2));
- if (e1.getLength() < e2.getLength()) {
+ for (size_t i1 = 0, i2 = 0; i1 != std::u16string_view::npos || i2 != std::u16string_view::npos;) {
+ std::u16string_view e1(getElement(version1, &i1));
+ std::u16string_view e2(getElement(version2, &i2));
+ if (e1.size() < e2.size()) {
return -1;
- } else if (e1.getLength() > e2.getLength()) {
+ } else if (e1.size() > e2.size()) {
return 1;
} else if (e1 < e2) {
return -1;
@@ -131,7 +131,7 @@ static void ImplFillElementList(
}
-bool DocumentSignatureHelper::isODFPre_1_2(const OUString & sVersion)
+bool DocumentSignatureHelper::isODFPre_1_2(std::u16string_view sVersion)
{
//The property version exists only if the document is at least version 1.2
//That is, if the document has version 1.1 and sVersion is empty.
@@ -148,9 +148,9 @@ bool DocumentSignatureHelper::isOOo3_2_Signature(const SignatureInformation & si
DocumentSignatureAlgorithm
DocumentSignatureHelper::getDocumentAlgorithm(
- const OUString & sODFVersion, const SignatureInformation & sigInfo)
+ std::u16string_view sODFVersion, const SignatureInformation & sigInfo)
{
- OSL_ASSERT(!sODFVersion.isEmpty());
+ OSL_ASSERT(!sODFVersion.empty());
DocumentSignatureAlgorithm mode = DocumentSignatureAlgorithm::OOo3_2;
if (!isOOo3_2_Signature(sigInfo))
{
@@ -423,7 +423,7 @@ SignatureStreamHelper DocumentSignatureHelper::OpenSignatureStream(
/** Check whether the current file can be signed with GPG (only ODF >= 1.2 can currently) */
bool DocumentSignatureHelper::CanSignWithGPG(
const Reference < css::embed::XStorage >& rxStore,
- const OUString& sOdfVersion)
+ std::u16string_view sOdfVersion)
{
if (!rxStore.is())
return false;
diff --git a/xmlsecurity/source/helper/xmlsignaturehelper.cxx b/xmlsecurity/source/helper/xmlsignaturehelper.cxx
index fbad3216d2aa..70b2ed0a9eb8 100644
--- a/xmlsecurity/source/helper/xmlsignaturehelper.cxx
+++ b/xmlsecurity/source/helper/xmlsignaturehelper.cxx
@@ -71,7 +71,7 @@ XMLSignatureHelper::~XMLSignatureHelper()
void XMLSignatureHelper::SetStorage(
const Reference < css::embed::XStorage >& rxStorage,
- const OUString& sODFVersion)
+ std::u16string_view sODFVersion)
{
SAL_WARN_IF( mxUriBinding.is(), "xmlsecurity.helper", "SetStorage - UriBinding already set!" );
mxUriBinding = new UriBindingHelper( rxStorage );
diff --git a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx
index e1b62e13c0f5..79441da1edf5 100644
--- a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx
+++ b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx
@@ -513,18 +513,18 @@ namespace xmlsecurity {
// https://datatracker.ietf.org/doc/html/rfc1485
// https://docs.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-certnametostra#CERT_X500_NAME_STR
// the main problem appears to be that in values " is escaped as "" vs. \"
-static OUString CompatDNCryptoAPI(OUString const& rDN)
+static OUString CompatDNCryptoAPI(std::u16string_view rDN)
{
- OUStringBuffer buf(rDN.getLength());
+ OUStringBuffer buf(rDN.size());
enum { DEFAULT, INVALUE, INQUOTE } state(DEFAULT);
- for (sal_Int32 i = 0; i < rDN.getLength(); ++i)
+ for (size_t i = 0; i < rDN.size(); ++i)
{
if (state == DEFAULT)
{
buf.append(rDN[i]);
if (rDN[i] == '=')
{
- if (rDN.getLength() == i+1)
+ if (rDN.size() == i+1)
{
break; // invalid?
}
@@ -553,7 +553,7 @@ static OUString CompatDNCryptoAPI(OUString const& rDN)
assert(state == INQUOTE);
if (rDN[i] == '"')
{
- if (rDN.getLength() != i+1 && rDN[i+1] == '"')
+ if (rDN.size() != i+1 && rDN[i+1] == '"')
{
buf.append('\\');
buf.append(rDN[i+1]);
@@ -597,7 +597,7 @@ bool EqualDistinguishedNames(
if (!ret && eMode == COMPAT_2ND)
{
CERTName *const pName2Compat(CERT_AsciiToName(OUStringToOString(
- CompatDNCryptoAPI(OUString(rName2)), RTL_TEXTENCODING_UTF8).getStr()));
+ CompatDNCryptoAPI(rName2), RTL_TEXTENCODING_UTF8).getStr()));
if (pName2Compat == nullptr)
{
CERT_DestroyName(pName1);