[poppler] 4 commits - poppler/Form.cc poppler/Form.h utils/numberofcharacters.h utils/pdfsig.1 utils/pdfsig.cc utils/pdftocairo.cc utils/pdftoppm.cc
Albert Astals Cid
aacid at kemper.freedesktop.org
Tue Apr 17 09:12:53 UTC 2018
poppler/Form.cc | 8 +++++++-
poppler/Form.h | 7 +++++--
utils/numberofcharacters.h | 26 ++++++++++++++++++++++++++
utils/pdfsig.1 | 3 +++
utils/pdfsig.cc | 40 ++++++++++++++++++++++++++++++++++++++--
utils/pdftocairo.cc | 13 +------------
utils/pdftoppm.cc | 13 +------------
7 files changed, 81 insertions(+), 29 deletions(-)
New commits:
commit 3636ccbaece6706ef86dfab9303c3f164e68ffe2
Author: Albert Astals Cid <aacid at kde.org>
Date: Tue Apr 17 10:57:06 2018 +0200
pdfsig: Don't use fixed buffer size for path
diff --git a/utils/pdfsig.cc b/utils/pdfsig.cc
index 16250e98..c4e52fd8 100644
--- a/utils/pdfsig.cc
+++ b/utils/pdfsig.cc
@@ -33,6 +33,7 @@
#include "GlobalParams.h"
#include "SignatureInfo.h"
#include "Win32Console.h"
+#include "numberofcharacters.h"
static const char * getReadableSigState(SignatureValidationStatus sig_vs)
{
@@ -90,7 +91,7 @@ static char *getReadableTime(time_t unix_time)
return time_str;
}
-static void dumpSignature(int sig_num, FormWidgetSignature *sig_widget, const char *filename)
+static void dumpSignature(int sig_num, int sigCount, FormWidgetSignature *sig_widget, const char *filename)
{
const GooString *signature = sig_widget->getSignature();
if (!signature) {
@@ -98,12 +99,18 @@ static void dumpSignature(int sig_num, FormWidgetSignature *sig_widget, const ch
return;
}
- char buf[1024];
- snprintf(buf, sizeof buf, "%s.sig%02u", basename(filename), sig_num);
- printf("Signature #%d (%u bytes) => %s\n", sig_num, signature->getLength(), buf);
- std::ofstream outfile(buf, std::ofstream::binary);
+ const int sigCountLength = numberOfCharacters(sigCount);
+ // We want format to be {0:s}.sig{1:Xd} where X is sigCountLength
+ // since { is the magic character to replace things we need to put it twice where
+ // we don't want it to be replaced
+ GooString *format = GooString::format("{{0:s}}.sig{{1:{0:d}d}}", sigCountLength);
+ GooString *path = GooString::format(format->getCString(), basename(filename), sig_num);
+ printf("Signature #%d (%u bytes) => %s\n", sig_num, signature->getLength(), path->getCString());
+ std::ofstream outfile(path->getCString(), std::ofstream::binary);
outfile.write(signature->getCString(), signature->getLength());
outfile.close();
+ delete format;
+ delete path;
}
static GBool printVersion = gFalse;
@@ -174,7 +181,7 @@ int main(int argc, char *argv[])
if (dumpSignatures) {
printf("Dumping Signatures: %u\n", sigCount);
for (unsigned int i = 0; i < sigCount; i++) {
- dumpSignature(i, sig_widgets.at(i), fileName->getCString());
+ dumpSignature(i, sigCount, sig_widgets.at(i), fileName->getCString());
}
goto end;
} else {
commit 17c7e3b0e1801a8643712013eb3b106c802e0faa
Author: Albert Astals Cid <aacid at kde.org>
Date: Tue Apr 17 11:02:29 2018 +0200
utils: Move numberOfCharacters to shared file
diff --git a/utils/numberofcharacters.h b/utils/numberofcharacters.h
new file mode 100644
index 00000000..1b01faba
--- /dev/null
+++ b/utils/numberofcharacters.h
@@ -0,0 +1,26 @@
+//========================================================================
+//
+// pdfsig.cc
+//
+// This file is licensed under the GPLv2 or later
+//
+// Copyright (C) 2010 Albert Astals Cid <aacid at kde.org>
+//
+//========================================================================
+
+#ifndef NUMBEROFCHARACTERS_H
+#define NUMBEROFCHARACTERS_H
+
+static int numberOfCharacters(unsigned int n)
+{
+ int charNum = 0;
+ while (n >= 10)
+ {
+ n = n / 10;
+ charNum++;
+ }
+ charNum++;
+ return charNum;
+}
+
+#endif
diff --git a/utils/pdftocairo.cc b/utils/pdftocairo.cc
index 72a6e7e1..05ceaa3b 100644
--- a/utils/pdftocairo.cc
+++ b/utils/pdftocairo.cc
@@ -56,6 +56,7 @@
#include "PDFDocFactory.h"
#include "CairoOutputDev.h"
#include "Win32Console.h"
+#include "numberofcharacters.h"
#ifdef USE_CMS
#include <lcms2.h>
#endif
@@ -804,18 +805,6 @@ static GBool setPSPaperSize(char *size, int &psPaperWidth, int &psPaperHeight) {
return gTrue;
}
-static int numberOfCharacters(unsigned int n)
-{
- int charNum = 0;
- while (n >= 10)
- {
- n = n / 10;
- charNum++;
- }
- charNum++;
- return charNum;
-}
-
static GooString *getImageFileName(GooString *outputFileName, int numDigits, int page)
{
char buf[10];
diff --git a/utils/pdftoppm.cc b/utils/pdftoppm.cc
index 80336eb8..4d567bd4 100644
--- a/utils/pdftoppm.cc
+++ b/utils/pdftoppm.cc
@@ -52,6 +52,7 @@
#include "splash/Splash.h"
#include "SplashOutputDev.h"
#include "Win32Console.h"
+#include "numberofcharacters.h"
// Uncomment to build pdftoppm with pthreads
// You may also have to change the buildsystem to
@@ -366,18 +367,6 @@ static void processPageJobs() {
#endif // UTILS_USE_PTHREADS
-static int numberOfCharacters(unsigned int n)
-{
- int charNum = 0;
- while (n >= 10)
- {
- n = n / 10;
- charNum++;
- }
- charNum++;
- return charNum;
-}
-
int main(int argc, char *argv[]) {
PDFDoc *doc;
GooString *fileName = nullptr;
commit 73ab9930810ae83998467ec859f3ee3984548cbd
Author: Albert Astals Cid <aacid at kde.org>
Date: Tue Apr 17 10:46:46 2018 +0200
pdfsig: Add -dump to manpage
diff --git a/utils/pdfsig.1 b/utils/pdfsig.1
index 99ca056d..0a5cc62d 100644
--- a/utils/pdfsig.1
+++ b/utils/pdfsig.1
@@ -25,6 +25,9 @@ The NSS Certificate database in /etc/pki/nssdb.
.B \-nocert
Do not validate the certificate.
.TP
+.B \-dump
+Dump all signatures into current directory.
+.TP
.B \-v
Print copyright and version information.
.TP
commit bdece3bb0c115576d23e76dc29ee43f04aafdee0
Author: Chinmoy Ranjan Pradhan <chinmoyrp65 at protonmail.com>
Date: Tue Apr 17 10:45:15 2018 +0200
pdfsig: Add -dump which writes signatures to disk
Bug #104881
diff --git a/poppler/Form.cc b/poppler/Form.cc
index 6aff30d1..85045b8e 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -20,7 +20,8 @@
// Copyright 2017 Hans-Ulrich Jüttner <huj at froreich-bioscientia.de>
// Copyright 2017 Bernd Kuhls <berndkuhls at hotmail.com>
// Copyright 2018 Andre Heinecke <aheinecke at intevation.de>
-// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>. Work sponsored by the LiMux project of the city of Munich
+// Copyright 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>. Work sponsored by the LiMux project of the city of Munich
+// Copyright 2018 Chinmoy Ranjan Pradhan <chinmoyrp65 at protonmail.com>
//
//========================================================================
@@ -461,6 +462,11 @@ FormWidgetSignature::FormWidgetSignature(PDFDoc *docA, Object *aobj, unsigned nu
type = formSignature;
}
+const GooString *FormWidgetSignature::getSignature() const
+{
+ return static_cast<FormFieldSignature*>(field)->getSignature();
+}
+
SignatureInfo *FormWidgetSignature::validateSignature(bool doVerifyCert, bool forceRevalidation, time_t validationTime)
{
return static_cast<FormFieldSignature*>(field)->validateSignature(doVerifyCert, forceRevalidation, validationTime);
diff --git a/poppler/Form.h b/poppler/Form.h
index 9df6b22e..681d1db4 100644
--- a/poppler/Form.h
+++ b/poppler/Form.h
@@ -16,7 +16,8 @@
// Copyright 2017 Roland Hieber <r.hieber at pengutronix.de>
// Copyright 2017 Hans-Ulrich Jüttner <huj at froreich-bioscientia.de>
// Copyright 2018 Andre Heinecke <aheinecke at intevation.de>
-// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>. Work sponsored by the LiMux project of the city of Munich
+// Copyright 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>. Work sponsored by the LiMux project of the city of Munich
+// Copyright 2018 Chinmoy Ranjan Pradhan <chinmoyrp65 at protonmail.com>
//
//========================================================================
@@ -283,6 +284,8 @@ public:
// if the check passed (and the checked file size as output parameter in checkedFileSize)
// otherwise a nullptr is returned
GooString* getCheckedSignature(Goffset *checkedFileSize);
+
+ const GooString *getSignature() const;
};
//------------------------------------------------------------------------
@@ -540,7 +543,7 @@ public:
~FormFieldSignature();
Object* getByteRange() { return &byte_range; }
- GooString* getSignature() { return signature; }
+ const GooString* getSignature() const { return signature; }
private:
void parseInfo();
diff --git a/utils/pdfsig.cc b/utils/pdfsig.cc
index 2f08c82a..16250e98 100644
--- a/utils/pdfsig.cc
+++ b/utils/pdfsig.cc
@@ -9,7 +9,8 @@
// Copyright 2015, 2017, 2018 Albert Astals Cid <aacid at kde.org>
// Copyright 2016 Markus Kilås <digital at markuspage.com>
// Copyright 2017 Hans-Ulrich Jüttner <huj at froreich-bioscientia.de>
-// Copyright (C) 2017 Adrian Johnson <ajohnson at redneon.com>
+// Copyright 2017 Adrian Johnson <ajohnson at redneon.com>
+// Copyright 2018 Chinmoy Ranjan Pradhan <chinmoyrp65 at protonmail.com>
//
//========================================================================
@@ -21,6 +22,7 @@
#include <string.h>
#include <time.h>
#include <hasht.h>
+#include <fstream>
#include "parseargs.h"
#include "Object.h"
#include "Array.h"
@@ -88,13 +90,32 @@ static char *getReadableTime(time_t unix_time)
return time_str;
}
+static void dumpSignature(int sig_num, FormWidgetSignature *sig_widget, const char *filename)
+{
+ const GooString *signature = sig_widget->getSignature();
+ if (!signature) {
+ printf("Cannot dump signature #%d\n", sig_num);
+ return;
+ }
+
+ char buf[1024];
+ snprintf(buf, sizeof buf, "%s.sig%02u", basename(filename), sig_num);
+ printf("Signature #%d (%u bytes) => %s\n", sig_num, signature->getLength(), buf);
+ std::ofstream outfile(buf, std::ofstream::binary);
+ outfile.write(signature->getCString(), signature->getLength());
+ outfile.close();
+}
+
static GBool printVersion = gFalse;
static GBool printHelp = gFalse;
static GBool dontVerifyCert = gFalse;
+static GBool dumpSignatures = gFalse;
static const ArgDesc argDesc[] = {
{"-nocert", argFlag, &dontVerifyCert, 0,
"don't perform certificate validation"},
+ {"-dump", argFlag, &dumpSignatures, 0,
+ "dump all signatures into current directory"},
{"-v", argFlag, &printVersion, 0,
"print copyright and version info"},
@@ -150,7 +171,15 @@ int main(int argc, char *argv[])
sigCount = sig_widgets.size();
if (sigCount >= 1) {
- printf("Digital Signature Info of: %s\n", fileName->getCString());
+ if (dumpSignatures) {
+ printf("Dumping Signatures: %u\n", sigCount);
+ for (unsigned int i = 0; i < sigCount; i++) {
+ dumpSignature(i, sig_widgets.at(i), fileName->getCString());
+ }
+ goto end;
+ } else {
+ printf("Digital Signature Info of: %s\n", fileName->getCString());
+ }
} else {
printf("File '%s' does not contain any signatures\n", fileName->getCString());
exitCode = 2;
More information about the poppler
mailing list