xmlsecurity PDF sign: improve suggested signature ID
So that when we have a single signature with ID="Signature2", then we use "Signature3" for the next ID, not "Signature2". (Acrobat uses that ID for the first signature.) Change-Id: I7032fbf014184da2a5be24730a92abc32a9a1258 Reviewed-on: https://gerrit.libreoffice.org/30725 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
This commit is contained in:
@@ -113,6 +113,8 @@ class XMLSECURITY_DLLPUBLIC PDFDocument
|
|||||||
static int AsHex(char ch);
|
static int AsHex(char ch);
|
||||||
/// Decode a hex dump.
|
/// Decode a hex dump.
|
||||||
static std::vector<unsigned char> DecodeHexString(PDFHexStringElement* pElement);
|
static std::vector<unsigned char> DecodeHexString(PDFHexStringElement* pElement);
|
||||||
|
/// Suggest a minimal, yet free signature ID to use for the next signature.
|
||||||
|
sal_uInt32 GetNextSignature();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PDFDocument();
|
PDFDocument();
|
||||||
|
@@ -335,11 +335,30 @@ bool PDFDocument::RemoveSignature(size_t nPosition)
|
|||||||
return m_aEditBuffer.good();
|
return m_aEditBuffer.good();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sal_uInt32 PDFDocument::GetNextSignature()
|
||||||
|
{
|
||||||
|
sal_uInt32 nRet = 0;
|
||||||
|
for (const auto& pSignature : GetSignatureWidgets())
|
||||||
|
{
|
||||||
|
auto pT = dynamic_cast<PDFLiteralStringElement*>(pSignature->Lookup("T"));
|
||||||
|
if (!pT)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const OString& rValue = pT->GetValue();
|
||||||
|
const OString aPrefix = "Signature";
|
||||||
|
if (!rValue.startsWith(aPrefix))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
nRet = std::max(nRet, rValue.copy(aPrefix.getLength()).toUInt32());
|
||||||
|
}
|
||||||
|
|
||||||
|
return nRet + 1;
|
||||||
|
}
|
||||||
|
|
||||||
bool PDFDocument::Sign(const uno::Reference<security::XCertificate>& xCertificate, const OUString& rDescription)
|
bool PDFDocument::Sign(const uno::Reference<security::XCertificate>& xCertificate, const OUString& rDescription)
|
||||||
{
|
{
|
||||||
// Decide what identifier to use for the new signature.
|
// Decide what identifier to use for the new signature.
|
||||||
std::vector<PDFObjectElement*> aSignatures = GetSignatureWidgets();
|
sal_uInt32 nNextSignature = GetNextSignature();
|
||||||
sal_uInt32 nNextSignature = aSignatures.size() + 1;
|
|
||||||
|
|
||||||
m_aEditBuffer.Seek(STREAM_SEEK_TO_END);
|
m_aEditBuffer.Seek(STREAM_SEEK_TO_END);
|
||||||
m_aEditBuffer.WriteCharPtr("\n");
|
m_aEditBuffer.WriteCharPtr("\n");
|
||||||
|
Reference in New Issue
Block a user