Replace 3-parameter CPDF_String ctor

Replace the 3-parameter CPDF_String ctor with a different 3-parameter
ctor that takes a span<const uint8_t> and a placeholder. Update callers
to use some kind of a uint8_t data container instead of stuffing the
data into a ByteString.

Change-Id: I168d1e4b42bbf804758f65ecfead23097a8526c5
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/119372
Reviewed-by: Thomas Sepez <tsepez@google.com>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/fpdf_attachment.cpp b/fpdfsdk/fpdf_attachment.cpp
index 89b71f9..ccc2154 100644
--- a/fpdfsdk/fpdf_attachment.cpp
+++ b/fpdfsdk/fpdf_attachment.cpp
@@ -6,6 +6,7 @@
 
 #include <limits.h>
 
+#include <array>
 #include <memory>
 #include <utility>
 
@@ -33,11 +34,6 @@
 
 constexpr char kChecksumKey[] = "CheckSum";
 
-ByteString CFXByteStringHexDecode(const ByteString& bsHex) {
-  DataAndBytesConsumed result = HexDecode(bsHex.unsigned_span());
-  return ByteString(ByteStringView(result.data));
-}
-
 }  // namespace
 
 FPDF_EXPORT int FPDF_CALLCONV
@@ -162,11 +158,13 @@
   // SAFETY: required from caller.
   ByteString bsValue = UNSAFE_BUFFERS(ByteStringFromFPDFWideString(value));
   ByteString bsKey = key;
-  bool bEncodedAsHex = bsKey == kChecksumKey;
-  if (bEncodedAsHex) {
-    bsValue = CFXByteStringHexDecode(bsValue);
+  if (bsKey == kChecksumKey) {
+    pParamsDict->SetNewFor<CPDF_String>(bsKey,
+                                        HexDecode(bsValue.unsigned_span()).data,
+                                        CPDF_String::DataType::kIsHex);
+  } else {
+    pParamsDict->SetNewFor<CPDF_String>(bsKey, bsValue);
   }
-  pParamsDict->SetNewFor<CPDF_String>(bsKey, bsValue, bEncodedAsHex);
   return true;
 }
 
@@ -239,15 +237,12 @@
   pdfium::span<const uint8_t> contents_span = UNSAFE_BUFFERS(
       pdfium::make_span(static_cast<const uint8_t*>(contents), len));
 
-  ByteString digest;
-  {
-    auto digest_span = pdfium::as_writable_bytes(digest.GetBuffer(16));
-    CRYPT_MD5Generate(contents_span, digest_span.data());
-    digest.ReleaseBuffer(16);
-  }
+  std::array<uint8_t, 16> digest;
+  CRYPT_MD5Generate(contents_span, digest.data());
 
   // Set the checksum of the new attachment in the dictionary.
-  pParamsDict->SetNewFor<CPDF_String>(kChecksumKey, digest, /*bHex=*/true);
+  pParamsDict->SetNewFor<CPDF_String>(kChecksumKey, digest,
+                                      CPDF_String::DataType::kIsHex);
 
   // Create the file stream and have the filespec dictionary link to it.
   auto pFileStream = pDoc->NewIndirect<CPDF_Stream>(