summaryrefslogtreecommitdiff
path: root/xmlsecurity/source/xmlsec/nss
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-10-29 10:29:41 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2021-11-01 09:55:03 +0100
commitd12f25905c3d7e474b603a716669b12143b6c34a (patch)
treee6050b21f43f09bf5105b0a073ef8dc3ae3fbe55 /xmlsecurity/source/xmlsec/nss
parentf16f35d40948bd4bbe835e0ba3c2f75aa0de23f7 (diff)
Prepare for removal of non-const operator[] from Sequence in xmlsecurity
Change-Id: I7cfcf9f9ea307bd737292e6f4f37a29f453167c6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124418 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'xmlsecurity/source/xmlsec/nss')
-rw-r--r--xmlsecurity/source/xmlsec/nss/ciphercontext.cxx5
-rw-r--r--xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.cxx6
-rw-r--r--xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx18
-rw-r--r--xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx47
4 files changed, 22 insertions, 54 deletions
diff --git a/xmlsecurity/source/xmlsec/nss/ciphercontext.cxx b/xmlsecurity/source/xmlsec/nss/ciphercontext.cxx
index c36de660df4e..c4d1c6113bf6 100644
--- a/xmlsecurity/source/xmlsec/nss/ciphercontext.cxx
+++ b/xmlsecurity/source/xmlsec/nss/ciphercontext.cxx
@@ -200,14 +200,15 @@ uno::Sequence< ::sal_Int8 > SAL_CALL OCipherContext::finalizeCipherContextAndDis
sal_Int32 nPaddingSize = m_nBlockSize - nSizeForPadding;
sal_Int32 nOldLastBlockLen = m_aLastBlock.getLength();
m_aLastBlock.realloc( nOldLastBlockLen + nPaddingSize );
+ auto pLastBlock = m_aLastBlock.getArray();
if ( nPaddingSize > 1 )
{
rtlRandomPool aRandomPool = rtl_random_createPool();
- rtl_random_getBytes( aRandomPool, m_aLastBlock.getArray() + nOldLastBlockLen, nPaddingSize - 1 );
+ rtl_random_getBytes( aRandomPool, pLastBlock + nOldLastBlockLen, nPaddingSize - 1 );
rtl_random_destroyPool ( aRandomPool );
}
- m_aLastBlock[m_aLastBlock.getLength() - 1] = static_cast< sal_Int8 >( nPaddingSize );
+ pLastBlock[m_aLastBlock.getLength() - 1] = static_cast< sal_Int8 >( nPaddingSize );
}
// finally should the last block be smaller than two standard blocks
diff --git a/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.cxx
index 5827c5f92272..e37a5473ceb8 100644
--- a/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.cxx
+++ b/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.cxx
@@ -84,8 +84,9 @@ css::uno::Sequence< css::security::CertAltNameEntry > SAL_CALL SanExtensionImpl:
otherNameProp.Name = OUString::createFromAscii(CERT_GetOidString(&current->name.OthName.oid));
Sequence< sal_Int8 > otherName( current->name.OthName.name.len ) ;
+ auto otherNameRange = asNonConstRange(otherName);
for( unsigned int r = 0; r < current->name.OthName.name.len ; r ++ )
- otherName[r] = *( current->name.OthName.name.data + r ) ;
+ otherNameRange[r] = *( current->name.OthName.name.data + r ) ;
otherNameProp.Value <<= otherName;
@@ -123,8 +124,9 @@ css::uno::Sequence< css::security::CertAltNameEntry > SAL_CALL SanExtensionImpl:
m_Entries[i].Type = ExtAltNameType_IP_ADDRESS;
Sequence< sal_Int8 > ipAddress( current->name.other.len ) ;
+ auto ipAddressRange = asNonConstRange(ipAddress);
for( unsigned int r = 0; r < current->name.other.len ; r ++ )
- ipAddress[r] = *( current->name.other.data + r ) ;
+ ipAddressRange[r] = *( current->name.other.data + r ) ;
m_Entries[i].Value <<= ipAddress;
break;
diff --git a/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx
index 94200051d57d..f6c35257f80f 100644
--- a/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx
+++ b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx
@@ -263,7 +263,6 @@ void SecurityEnvironment_NssImpl::updateSlots()
Sequence< Reference < XCertificate > >
SecurityEnvironment_NssImpl::getPersonalCertificates()
{
- sal_Int32 length ;
std::vector< rtl::Reference<X509Certificate_NssImpl> > certsList ;
updateSlots();
@@ -299,17 +298,8 @@ SecurityEnvironment_NssImpl::getPersonalCertificates()
}
- length = certsList.size() ;
- if( length != 0 ) {
- int i = 0;
- Sequence< Reference< XCertificate > > certSeq( length ) ;
-
- for( const auto& rXCert : certsList ) {
- certSeq[i] = rXCert ;
- ++i;
- }
-
- return certSeq ;
+ if( certsList.size() != 0 ) {
+ return comphelper::containerToSequence<Reference< XCertificate >>(certsList) ;
}
return Sequence< Reference < XCertificate > > ();
@@ -488,9 +478,7 @@ Reference< XCertificate > SecurityEnvironment_NssImpl::createCertificateFromAsci
if (certSize == 0)
return nullptr;
- Sequence< sal_Int8 > rawCert(certSize) ;
- for (int i = 0 ; i < certSize; ++i)
- rawCert[i] = *( chCert + i ) ;
+ Sequence< sal_Int8 > rawCert(comphelper::arrayToSequence<sal_Int8>(chCert, certSize)) ;
xmlFree( chCert ) ;
diff --git a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx
index 67956e018e88..2d52134344fb 100644
--- a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx
+++ b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx
@@ -26,6 +26,7 @@
#include <pk11pub.h>
#include <sal/config.h>
+#include <comphelper/sequence.hxx>
#include <comphelper/servicehelper.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <rtl/ref.hxx>
@@ -72,11 +73,8 @@ sal_Int16 SAL_CALL X509Certificate_NssImpl::getVersion() {
css::uno::Sequence< sal_Int8 > SAL_CALL X509Certificate_NssImpl::getSerialNumber() {
if( m_pCert != nullptr && m_pCert->serialNumber.len > 0 ) {
- Sequence< sal_Int8 > serial( m_pCert->serialNumber.len ) ;
- for( unsigned int i = 0 ; i < m_pCert->serialNumber.len ; i ++ )
- serial[i] = *( m_pCert->serialNumber.data + i ) ;
-
- return serial ;
+ return comphelper::arrayToSequence<sal_Int8>(m_pCert->serialNumber.data,
+ m_pCert->serialNumber.len) ;
} else {
return css::uno::Sequence< sal_Int8 >();
}
@@ -158,11 +156,7 @@ css::util::DateTime SAL_CALL X509Certificate_NssImpl::getNotValidAfter() {
css::uno::Sequence< sal_Int8 > SAL_CALL X509Certificate_NssImpl::getIssuerUniqueID() {
if( m_pCert != nullptr && m_pCert->issuerID.len > 0 ) {
- Sequence< sal_Int8 > issuerUid( m_pCert->issuerID.len ) ;
- for( unsigned int i = 0 ; i < m_pCert->issuerID.len ; i ++ )
- issuerUid[i] = *( m_pCert->issuerID.data + i ) ;
-
- return issuerUid ;
+ return comphelper::arrayToSequence<sal_Int8>(m_pCert->issuerID.data, m_pCert->issuerID.len) ;
} else {
return css::uno::Sequence< sal_Int8 >();
}
@@ -170,11 +164,8 @@ css::uno::Sequence< sal_Int8 > SAL_CALL X509Certificate_NssImpl::getIssuerUnique
css::uno::Sequence< sal_Int8 > SAL_CALL X509Certificate_NssImpl::getSubjectUniqueID() {
if( m_pCert != nullptr && m_pCert->subjectID.len > 0 ) {
- Sequence< sal_Int8 > subjectUid( m_pCert->subjectID.len ) ;
- for( unsigned int i = 0 ; i < m_pCert->subjectID.len ; i ++ )
- subjectUid[i] = *( m_pCert->subjectID.data + i ) ;
-
- return subjectUid ;
+ return comphelper::arrayToSequence<sal_Int8>(m_pCert->subjectID.data,
+ m_pCert->subjectID.len) ;
} else {
return css::uno::Sequence< sal_Int8 >();
}
@@ -187,6 +178,7 @@ css::uno::Sequence< css::uno::Reference< css::security::XCertificateExtension >
for( len = 0, extns = m_pCert->extensions; *extns != nullptr; len ++, extns ++ ) ;
Sequence< Reference< XCertificateExtension > > xExtns( len ) ;
+ auto xExtnsRange = asNonConstRange(xExtns);
for( extns = m_pCert->extensions, len = 0; *extns != nullptr; extns ++, len ++ ) {
const SECItem id = (*extns)->id;
@@ -215,13 +207,13 @@ css::uno::Sequence< css::uno::Reference< css::security::XCertificateExtension >
{
rtl::Reference<SanExtensionImpl> pExtn = new SanExtensionImpl;
pExtn->setCertExtn(value, vlen, objid, objidlen, crit);
- xExtns[len] = pExtn ;
+ xExtnsRange[len] = pExtn ;
}
else
{
rtl::Reference<CertificateExtension_XmlSecImpl> pExtn = new CertificateExtension_XmlSecImpl;
pExtn->setCertExtn(value, vlen, objid, objidlen, crit);
- xExtns[len] = pExtn;
+ xExtnsRange[len] = pExtn;
}
}
@@ -283,12 +275,7 @@ css::uno::Reference< css::security::XCertificateExtension > SAL_CALL X509Certifi
css::uno::Sequence< sal_Int8 > SAL_CALL X509Certificate_NssImpl::getEncoded() {
if( m_pCert != nullptr && m_pCert->derCert.len > 0 ) {
- Sequence< sal_Int8 > rawCert( m_pCert->derCert.len ) ;
-
- for( unsigned int i = 0 ; i < m_pCert->derCert.len ; i ++ )
- rawCert[i] = *( m_pCert->derCert.data + i ) ;
-
- return rawCert ;
+ return comphelper::arrayToSequence<sal_Int8>(m_pCert->derCert.data, m_pCert->derCert.len) ;
} else {
return css::uno::Sequence< sal_Int8 >();
}
@@ -392,11 +379,7 @@ static css::uno::Sequence< sal_Int8 > getThumbprint(CERTCertificate const *pCert
rv = PK11_HashBuf(id, fingerprint, pCert->derCert.data, pCert->derCert.len);
if(rv == SECSuccess)
{
- Sequence< sal_Int8 > thumbprint( length ) ;
- for( int i = 0 ; i < length ; i ++ )
- thumbprint[i] = fingerprint[i];
-
- return thumbprint;
+ return comphelper::arrayToSequence<sal_Int8>(fingerprint, length);
}
}
return css::uno::Sequence< sal_Int8 >();
@@ -423,13 +406,7 @@ css::uno::Sequence< sal_Int8 > SAL_CALL X509Certificate_NssImpl::getSubjectPubli
if ( spk.len>0)
{
- Sequence< sal_Int8 > key( spk.len ) ;
- for( unsigned int i = 0 ; i < spk.len ; i ++ )
- {
- key[i] = *( spk.data + i ) ;
- }
-
- return key ;
+ return comphelper::arrayToSequence<sal_Int8>(spk.data, spk.len) ;
}
}