aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/qpdf/Pl_SHA2.hh
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2019-11-04 15:55:43 +0100
committerJay Berkenbilt <ejb@ql.org>2019-11-09 14:18:02 +0100
commitbb427bd11774f47f553257cdc0693f77b559654d (patch)
tree379100926074a82f81f24d0d6cbe41631b71cc50 /libqpdf/qpdf/Pl_SHA2.hh
parenteadc222ff9087c8dd41a7afced717a65802e849c (diff)
downloadqpdf-bb427bd11774f47f553257cdc0693f77b559654d.tar.zst
SHA2: switch to pluggable crypto
Diffstat (limited to 'libqpdf/qpdf/Pl_SHA2.hh')
-rw-r--r--libqpdf/qpdf/Pl_SHA2.hh43
1 files changed, 43 insertions, 0 deletions
diff --git a/libqpdf/qpdf/Pl_SHA2.hh b/libqpdf/qpdf/Pl_SHA2.hh
new file mode 100644
index 00000000..dea7141a
--- /dev/null
+++ b/libqpdf/qpdf/Pl_SHA2.hh
@@ -0,0 +1,43 @@
+#ifndef PL_SHA2_HH
+#define PL_SHA2_HH
+
+// Bits must be a supported number of bits, currently only 256, 384,
+// or 512. Passing 0 as bits leaves the pipeline uncommitted, in
+// which case resetBits must be called before the pipeline is used.
+// If a next is provided, this pipeline sends its output to its
+// successor unmodified. After calling finish, the SHA2 checksum of
+// the data that passed through the pipeline is available.
+
+// This pipeline is reusable; i.e., it is safe to call write() after
+// calling finish(). The first call to write() after a call to
+// finish() initializes a new SHA2 object. resetBits may also be
+// called between finish and the next call to write.
+
+#include <qpdf/Pipeline.hh>
+#include <qpdf/QPDFCryptoImpl.hh>
+#include <memory>
+
+class Pl_SHA2: public Pipeline
+{
+ public:
+ QPDF_DLL
+ Pl_SHA2(int bits = 0, Pipeline* next = 0);
+ QPDF_DLL
+ virtual ~Pl_SHA2();
+ QPDF_DLL
+ virtual void write(unsigned char*, size_t);
+ QPDF_DLL
+ virtual void finish();
+ QPDF_DLL
+ void resetBits(int bits);
+ QPDF_DLL
+ std::string getHexDigest();
+ QPDF_DLL
+ std::string getRawDigest();
+
+ private:
+ bool in_progress;
+ std::shared_ptr<QPDFCryptoImpl> crypto;
+};
+
+#endif // PL_SHA2_HH