aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/Pl_SHA2.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2013-01-25 14:59:55 +0100
committerJay Berkenbilt <ejb@ql.org>2013-03-04 22:45:15 +0100
commit32b62035ce9d5d07f7396cc50a0c38215f19c906 (patch)
treec7ade8bcf294574d731dc2bc7cdf42524ee023d2 /libqpdf/Pl_SHA2.cc
parent9f1594656cc4702b4b0e99a2787e18e4b00d54d3 (diff)
downloadqpdf-32b62035ce9d5d07f7396cc50a0c38215f19c906.tar.zst
Replace many calls to sprintf with QUtil::hex_encode
Add QUtil::hex_encode to encode binary data has a hexadecimal string, and use it in place of sprintf where possible.
Diffstat (limited to 'libqpdf/Pl_SHA2.cc')
-rw-r--r--libqpdf/Pl_SHA2.cc13
1 files changed, 2 insertions, 11 deletions
diff --git a/libqpdf/Pl_SHA2.cc b/libqpdf/Pl_SHA2.cc
index 018f411f..84f24d6e 100644
--- a/libqpdf/Pl_SHA2.cc
+++ b/libqpdf/Pl_SHA2.cc
@@ -2,6 +2,7 @@
#include <stdexcept>
#include <cstdio>
#include <qpdf/PointerHolder.hh>
+#include <qpdf/QUtil.hh>
Pl_SHA2::Pl_SHA2(int bits, Pipeline* next) :
Pipeline("sha2", next),
@@ -150,15 +151,5 @@ Pl_SHA2::getHexDigest()
throw std::logic_error(
"digest requested for in-progress SHA2 Pipeline");
}
- std::string raw = getRawDigest();
- size_t raw_size = raw.length();
- size_t hex_size = 1 + (2 * raw_size);
- PointerHolder<char> bufp(true, new char[hex_size]);
- char* buf = bufp.getPointer();
- buf[hex_size - 1] = '\0';
- for (unsigned int i = 0; i < raw_size; ++i)
- {
- std::sprintf(buf + i * 2, "%02x", (unsigned char)raw[i]);
- }
- return buf;
+ return QUtil::hex_encode(getRawDigest());
}