include/vcl/pdfwriter.hxx | 3 +++ vcl/source/gdi/pdfwriter_impl.cxx | 16 ++++++++-------- xmlsecurity/inc/pdfio/pdfdocument.hxx | 2 +- xmlsecurity/source/helper/pdfsignaturehelper.cxx | 2 +- xmlsecurity/source/pdfio/pdfdocument.cxx | 10 +++++++++- xmlsecurity/source/pdfio/pdfverify.cxx | 2 +- 6 files changed, 23 insertions(+), 12 deletions(-)
New commits: commit f7a6867d6ae88cd6ca9001c61880fc1511370b16 Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Thu Oct 20 17:09:04 2016 +0200 xmlsecurity: export description in PDF signature Extract appendUnicodeTextString() from the PDF writer impl, and reuse it in xmlsecurity, to share code. Change-Id: Icdc2f89132cd29e07280001e30bad97e0a644654 Reviewed-on: https://gerrit.libreoffice.org/30110 Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk> Tested-by: Jenkins <c...@libreoffice.org> diff --git a/include/vcl/pdfwriter.hxx b/include/vcl/pdfwriter.hxx index 6b9c529..79ac5db 100644 --- a/include/vcl/pdfwriter.hxx +++ b/include/vcl/pdfwriter.hxx @@ -1267,6 +1267,9 @@ The following structure describes the permissions used in PDF security /// Fill a PDF signature template. static bool Sign(PDFSignContext& rContext); + + /// Write rString as a PDF hex string into rBuffer. + static void AppendUnicodeTextString(const OUString& rString, OStringBuffer& rBuffer); }; } diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index b246263..c20446f 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -663,7 +663,7 @@ static void appendDestinationName( const OUString& rString, OStringBuffer& rBuff } //<--- i56629 -static void appendUnicodeTextString( const OUString& rString, OStringBuffer& rBuffer ) +void PDFWriter::AppendUnicodeTextString(const OUString& rString, OStringBuffer& rBuffer) { rBuffer.append( "FEFF" ); const sal_Unicode* pStr = rString.getStr(); @@ -1872,17 +1872,17 @@ void PDFWriterImpl::computeDocumentIdentifier( std::vector< sal_uInt8 >& o_rIden OString aInfoValuesOut; OStringBuffer aID( 1024 ); if( !i_rDocInfo.Title.isEmpty() ) - appendUnicodeTextString( i_rDocInfo.Title, aID ); + PDFWriter::AppendUnicodeTextString(i_rDocInfo.Title, aID); if( !i_rDocInfo.Author.isEmpty() ) - appendUnicodeTextString( i_rDocInfo.Author, aID ); + PDFWriter::AppendUnicodeTextString(i_rDocInfo.Author, aID); if( !i_rDocInfo.Subject.isEmpty() ) - appendUnicodeTextString( i_rDocInfo.Subject, aID ); + PDFWriter::AppendUnicodeTextString(i_rDocInfo.Subject, aID); if( !i_rDocInfo.Keywords.isEmpty() ) - appendUnicodeTextString( i_rDocInfo.Keywords, aID ); + PDFWriter::AppendUnicodeTextString(i_rDocInfo.Keywords, aID); if( !i_rDocInfo.Creator.isEmpty() ) - appendUnicodeTextString( i_rDocInfo.Creator, aID ); + PDFWriter::AppendUnicodeTextString(i_rDocInfo.Creator, aID); if( !i_rDocInfo.Producer.isEmpty() ) - appendUnicodeTextString( i_rDocInfo.Producer, aID ); + PDFWriter::AppendUnicodeTextString(i_rDocInfo.Producer, aID); TimeValue aTVal, aGMT; oslDateTime aDT; @@ -2025,7 +2025,7 @@ inline void PDFWriterImpl::appendUnicodeTextStringEncrypt( const OUString& rInSt } } else - appendUnicodeTextString( rInString, rOutBuffer ); + PDFWriter::AppendUnicodeTextString(rInString, rOutBuffer); rOutBuffer.append( ">" ); } diff --git a/xmlsecurity/inc/pdfio/pdfdocument.hxx b/xmlsecurity/inc/pdfio/pdfdocument.hxx index 2f95b7d..bb132a6 100644 --- a/xmlsecurity/inc/pdfio/pdfdocument.hxx +++ b/xmlsecurity/inc/pdfio/pdfdocument.hxx @@ -66,7 +66,7 @@ public: bool Read(SvStream& rStream); /// Sign the read document with xCertificate in the edit buffer. - bool Sign(const css::uno::Reference<css::security::XCertificate>& xCertificate); + bool Sign(const css::uno::Reference<css::security::XCertificate>& xCertificate, const OUString& rDescription); /// Serializes the contents of the edit buffer. bool Write(SvStream& rStream); std::vector<PDFObjectElement*> GetSignatureWidgets(); diff --git a/xmlsecurity/source/helper/pdfsignaturehelper.cxx b/xmlsecurity/source/helper/pdfsignaturehelper.cxx index 9529eef..fdd4ed8 100644 --- a/xmlsecurity/source/helper/pdfsignaturehelper.cxx +++ b/xmlsecurity/source/helper/pdfsignaturehelper.cxx @@ -131,7 +131,7 @@ bool PDFSignatureHelper::Sign(const uno::Reference<io::XInputStream>& xInputStre return false; } - if (!aDocument.Sign(m_xCertificate)) + if (!aDocument.Sign(m_xCertificate, m_aDescription)) { SAL_WARN("xmlsecurity.helper", "failed to sign"); return false; diff --git a/xmlsecurity/source/pdfio/pdfdocument.cxx b/xmlsecurity/source/pdfio/pdfdocument.cxx index fa5674c..57361f9 100644 --- a/xmlsecurity/source/pdfio/pdfdocument.cxx +++ b/xmlsecurity/source/pdfio/pdfdocument.cxx @@ -233,7 +233,7 @@ PDFDocument::PDFDocument() { } -bool PDFDocument::Sign(const uno::Reference<security::XCertificate>& xCertificate) +bool PDFDocument::Sign(const uno::Reference<security::XCertificate>& xCertificate, const OUString& rDescription) { m_aEditBuffer.WriteCharPtr("\n"); @@ -268,6 +268,14 @@ bool PDFDocument::Sign(const uno::Reference<security::XCertificate>& xCertificat aSigBuffer.append(aByteRangeFiller.makeStringAndClear()); // Finish the Sig obj. aSigBuffer.append(" /Filter/Adobe.PPKMS"); + + if (!rDescription.isEmpty()) + { + aSigBuffer.append("/Reason<"); + vcl::PDFWriter::AppendUnicodeTextString(rDescription, aSigBuffer); + aSigBuffer.append(">"); + } + aSigBuffer.append(" >>\nendobj\n\n"); m_aEditBuffer.WriteOString(aSigBuffer.toString()); diff --git a/xmlsecurity/source/pdfio/pdfverify.cxx b/xmlsecurity/source/pdfio/pdfverify.cxx index c751f20..5787aff 100644 --- a/xmlsecurity/source/pdfio/pdfverify.cxx +++ b/xmlsecurity/source/pdfio/pdfverify.cxx @@ -104,7 +104,7 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(nArgc, pArgv) SAL_WARN("xmlsecurity.pdfio", "no signing certificates found"); return 1; } - if (!aDocument.Sign(aCertificates[0])) + if (!aDocument.Sign(aCertificates[0], "pdfverify")) { SAL_WARN("xmlsecurity.pdfio", "failed to sign"); return 1; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits