poppler/Form.cc | 12 ++++++------ poppler/Form.h | 7 ++++--- qt5/src/poppler-form.cc | 5 ++--- qt6/src/poppler-form.cc | 5 ++--- utils/pdfsig.cc | 6 ++---- 5 files changed, 16 insertions(+), 19 deletions(-)
New commits: commit 5f52816b85c82eb41fdd4f4bf4020f8a679e931d Author: Albert Astals Cid <[email protected]> Date: Mon Jan 3 14:51:10 2022 +0100 Make FormFieldSignature::getCheckedSignature return an optional diff --git a/poppler/Form.cc b/poppler/Form.cc index f42801b4..f2b4815a 100644 --- a/poppler/Form.cc +++ b/poppler/Form.cc @@ -5,7 +5,7 @@ // This file is licensed under the GPLv2 or later // // Copyright 2006-2008 Julien Rebetez <[email protected]> -// Copyright 2007-2012, 2015-2021 Albert Astals Cid <[email protected]> +// Copyright 2007-2012, 2015-2022 Albert Astals Cid <[email protected]> // Copyright 2007-2008, 2011 Carlos Garcia Campos <[email protected]> // Copyright 2007, 2013, 2016, 2019 Adrian Johnson <[email protected]> // Copyright 2007 Iñigo Martínez <[email protected]> @@ -815,7 +815,7 @@ std::vector<Goffset> FormWidgetSignature::getSignedRangeBounds() const return static_cast<FormFieldSignature *>(field)->getSignedRangeBounds(); } -GooString *FormWidgetSignature::getCheckedSignature(Goffset *checkedFileSize) +std::optional<GooString> FormWidgetSignature::getCheckedSignature(Goffset *checkedFileSize) { return static_cast<FormFieldSignature *>(field)->getCheckedSignature(checkedFileSize); } @@ -2241,7 +2241,7 @@ std::vector<Goffset> FormFieldSignature::getSignedRangeBounds() const return range_vec; } -GooString *FormFieldSignature::getCheckedSignature(Goffset *checkedFileSize) +std::optional<GooString> FormFieldSignature::getCheckedSignature(Goffset *checkedFileSize) { Goffset start = 0; Goffset end = 0; @@ -2274,7 +2274,7 @@ GooString *FormFieldSignature::getCheckedSignature(Goffset *checkedFileSize) do { c1 = stream->getChar(); if (c1 == EOF) - return nullptr; + return {}; gstr.append(static_cast<char>(c1)); } while (++pos < len); if (gstr.getChar(0) == '3' && gstr.getChar(1) == '0') { @@ -2329,12 +2329,12 @@ GooString *FormFieldSignature::getCheckedSignature(Goffset *checkedFileSize) len = 0; } if (len > 0) { - return new GooString(&gstr, 0, len); + return GooString(&gstr, 0, len); } } } } - return nullptr; + return {}; } void FormFieldSignature::print(int indent) diff --git a/poppler/Form.h b/poppler/Form.h index 9f98c02e..a5ca8fdf 100644 --- a/poppler/Form.h +++ b/poppler/Form.h @@ -6,7 +6,7 @@ // // Copyright 2006 Julien Rebetez <[email protected]> // Copyright 2007, 2008, 2011 Carlos Garcia Campos <[email protected]> -// Copyright 2007-2010, 2012, 2015-2021 Albert Astals Cid <[email protected]> +// Copyright 2007-2010, 2012, 2015-2022 Albert Astals Cid <[email protected]> // Copyright 2010 Mark Riedesel <[email protected]> // Copyright 2011 Pino Toscano <[email protected]> // Copyright 2012 Fabio D'Urso <[email protected]> @@ -38,6 +38,7 @@ #include <ctime> +#include <optional> #include <set> #include <vector> @@ -316,7 +317,7 @@ public: // checks the length encoding of the signature and returns the hex encoded signature // if the check passed (and the checked file size as output parameter in checkedFileSize) // otherwise a nullptr is returned - GooString *getCheckedSignature(Goffset *checkedFileSize); + std::optional<GooString> getCheckedSignature(Goffset *checkedFileSize); const GooString *getSignature() const; @@ -607,7 +608,7 @@ public: // checks the length encoding of the signature and returns the hex encoded signature // if the check passed (and the checked file size as output parameter in checkedFileSize) // otherwise a nullptr is returned - GooString *getCheckedSignature(Goffset *checkedFileSize); + std::optional<GooString> getCheckedSignature(Goffset *checkedFileSize); ~FormFieldSignature() override; Object *getByteRange() { return &byte_range; } diff --git a/qt5/src/poppler-form.cc b/qt5/src/poppler-form.cc index 43ce0546..36f7b451 100644 --- a/qt5/src/poppler-form.cc +++ b/qt5/src/poppler-form.cc @@ -1,6 +1,6 @@ /* poppler-form.h: qt interface to poppler * Copyright (C) 2007-2008, 2011, Pino Toscano <[email protected]> - * Copyright (C) 2008, 2011, 2012, 2015-2021 Albert Astals Cid <[email protected]> + * Copyright (C) 2008, 2011, 2012, 2015-2022 Albert Astals Cid <[email protected]> * Copyright (C) 2011 Carlos Garcia Campos <[email protected]> * Copyright (C) 2012, Adam Reichold <[email protected]> * Copyright (C) 2016, Hanno Meyer-Thurow <[email protected]> @@ -1049,11 +1049,10 @@ SignatureValidationInfo FormFieldSignature::validate(int opt, const QDateTime &v priv->range_bounds.append(bound); } } - GooString *checkedSignature = fws->getCheckedSignature(&priv->docLength); + const std::optional<GooString> checkedSignature = fws->getCheckedSignature(&priv->docLength); if (priv->range_bounds.size() == 4 && checkedSignature) { priv->signature = QByteArray::fromHex(checkedSignature->c_str()); } - delete checkedSignature; return SignatureValidationInfo(priv); } diff --git a/qt6/src/poppler-form.cc b/qt6/src/poppler-form.cc index 1ed73fb8..d24e3892 100644 --- a/qt6/src/poppler-form.cc +++ b/qt6/src/poppler-form.cc @@ -1,6 +1,6 @@ /* poppler-form.h: qt interface to poppler * Copyright (C) 2007-2008, 2011, Pino Toscano <[email protected]> - * Copyright (C) 2008, 2011, 2012, 2015-2021 Albert Astals Cid <[email protected]> + * Copyright (C) 2008, 2011, 2012, 2015-2022 Albert Astals Cid <[email protected]> * Copyright (C) 2011 Carlos Garcia Campos <[email protected]> * Copyright (C) 2012, Adam Reichold <[email protected]> * Copyright (C) 2016, Hanno Meyer-Thurow <[email protected]> @@ -1049,11 +1049,10 @@ SignatureValidationInfo FormFieldSignature::validate(int opt, const QDateTime &v priv->range_bounds.append(bound); } } - GooString *checkedSignature = fws->getCheckedSignature(&priv->docLength); + const std::optional<GooString> checkedSignature = fws->getCheckedSignature(&priv->docLength); if (priv->range_bounds.size() == 4 && checkedSignature) { priv->signature = QByteArray::fromHex(checkedSignature->c_str()); } - delete checkedSignature; return SignatureValidationInfo(priv); } diff --git a/utils/pdfsig.cc b/utils/pdfsig.cc index a3dee865..fd96eaaa 100644 --- a/utils/pdfsig.cc +++ b/utils/pdfsig.cc @@ -375,9 +375,8 @@ int main(int argc, char *argv[]) FormFieldSignature *ffs = signatures.at(signatureNumber - 1); Goffset file_size = 0; - GooString *sig = ffs->getCheckedSignature(&file_size); + const std::optional<GooString> sig = ffs->getCheckedSignature(&file_size); if (sig) { - delete sig; printf("Signature number %d is already signed\n", signatureNumber); return 2; } @@ -468,13 +467,12 @@ int main(int argc, char *argv[]) if (ranges.size() == 4) { printf(" - Signed Ranges: [%lld - %lld], [%lld - %lld]\n", ranges[0], ranges[1], ranges[2], ranges[3]); Goffset checked_file_size; - GooString *signature = signatures.at(i)->getCheckedSignature(&checked_file_size); + const std::optional<GooString> signature = signatures.at(i)->getCheckedSignature(&checked_file_size); if (signature && checked_file_size == ranges[3]) { printf(" - Total document signed\n"); } else { printf(" - Not total document signed\n"); } - delete signature; } printf(" - Signature Validation: %s\n", getReadableSigState(sig_info->getSignatureValStatus())); gfree(time_str);
