5#include "public/fpdf_signature.h"
10#include "constants/form_fields.h"
11#include "core/fpdfapi/parser/cpdf_array.h"
12#include "core/fpdfapi/parser/cpdf_dictionary.h"
13#include "core/fpdfapi/parser/cpdf_document.h"
14#include "core/fxcrt/stl_util.h"
15#include "fpdfsdk/cpdfsdk_helpers.h"
16#include "third_party/base/numerics/safe_conversions.h"
20std::vector<RetainPtr<
const CPDF_Dictionary>> CollectSignatures(
22 std::vector<RetainPtr<
const CPDF_Dictionary>> signatures;
27 RetainPtr<
const CPDF_Dictionary> acro_form = root->GetDictFor(
"AcroForm");
31 RetainPtr<
const CPDF_Array> fields = acro_form->GetArrayFor(
"Fields");
36 for (
auto& field : locker) {
37 RetainPtr<
const CPDF_Dictionary> field_dict = field->GetDict();
38 if (field_dict && field_dict->GetNameFor(pdfium::form_fields::kFT) ==
39 pdfium::form_fields::kSig) {
40 signatures.push_back(std::move(field_dict));
53 return fxcrt::CollectionSize<
int>(CollectSignatures(doc));
62 std::vector<RetainPtr<
const CPDF_Dictionary>> signatures =
63 CollectSignatures(doc);
64 if (!
fxcrt::IndexInBounds(signatures, index))
67 return FPDFSignatureFromCPDFDictionary(signatures[index].Get());
73 unsigned long length) {
74 const CPDF_Dictionary* signature_dict =
79 RetainPtr<
const CPDF_Dictionary> value_dict =
80 signature_dict->GetDictFor(pdfium::form_fields::kV);
84 ByteString contents = value_dict->GetByteStringFor(
"Contents");
85 const unsigned long contents_len =
86 pdfium::base::checked_cast<
unsigned long>(contents.GetLength());
87 if (buffer && length >= contents_len)
88 memcpy(buffer, contents
.c_str(), contents_len);
96 unsigned long length) {
97 const CPDF_Dictionary* signature_dict =
102 RetainPtr<
const CPDF_Dictionary> value_dict =
103 signature_dict->GetDictFor(pdfium::form_fields::kV);
107 RetainPtr<
const CPDF_Array> byte_range = value_dict->GetArrayFor(
"ByteRange");
111 const unsigned long byte_range_len =
112 fxcrt::CollectionSize<
unsigned long>(*byte_range);
113 if (buffer && length >= byte_range_len) {
114 for (size_t i = 0; i < byte_range_len; ++i)
115 buffer[i] = byte_range->GetIntegerAt(i);
117 return byte_range_len;
123 unsigned long length) {
124 const CPDF_Dictionary* signature_dict =
129 RetainPtr<
const CPDF_Dictionary> value_dict =
130 signature_dict->GetDictFor(pdfium::form_fields::kV);
131 if (!value_dict || !value_dict->KeyExist(
"SubFilter"))
134 ByteString sub_filter = value_dict->GetNameFor(
"SubFilter");
141 unsigned long length) {
142 const CPDF_Dictionary* signature_dict =
147 RetainPtr<
const CPDF_Dictionary> value_dict =
148 signature_dict->GetDictFor(pdfium::form_fields::kV);
153 if (!obj || !obj->IsString())
156 return Utf16EncodeMaybeCopyAndReturnLength(obj->GetUnicodeText(), buffer,
163 unsigned long length) {
164 const CPDF_Dictionary* signature_dict =
169 RetainPtr<
const CPDF_Dictionary> value_dict =
170 signature_dict->GetDictFor(pdfium::form_fields::kV);
175 if (!obj || !obj->IsString())
178 return NulTerminateMaybeCopyAndReturnLength(obj->GetString(), buffer, length);
184 const CPDF_Dictionary* signature_dict =
189 RetainPtr<
const CPDF_Dictionary> value_dict =
190 signature_dict->GetDictFor(pdfium::form_fields::kV);
194 RetainPtr<
const CPDF_Array> references = value_dict->GetArrayFor(
"Reference");
199 for (
auto& reference : locker) {
200 RetainPtr<
const CPDF_Dictionary> reference_dict = reference->GetDict();
204 ByteString transform_method = reference_dict->GetNameFor(
"TransformMethod");
205 if (transform_method !=
"DocMDP")
208 RetainPtr<
const CPDF_Dictionary> transform_params =
209 reference_dict->GetDictFor(
"TransformParams");
210 if (!transform_params)
214 permission = transform_params->GetIntegerFor(
"P", 2);
215 if (permission < 1 || permission > 3)
const CPDF_Dictionary * GetRoot() const
const char * c_str() const
unsigned long NulTerminateMaybeCopyAndReturnLength(const ByteString &text, void *buffer, unsigned long buflen)
const CPDF_Dictionary * CPDFDictionaryFromFPDFSignature(FPDF_SIGNATURE signature)
CPDF_Document * CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc)
FPDF_EXPORT unsigned int FPDF_CALLCONV FPDFSignatureObj_GetDocMDPPermission(FPDF_SIGNATURE signature)
FPDF_EXPORT FPDF_SIGNATURE FPDF_CALLCONV FPDF_GetSignatureObject(FPDF_DOCUMENT document, int index)
FPDF_EXPORT int FPDF_CALLCONV FPDF_GetSignatureCount(FPDF_DOCUMENT document)
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFSignatureObj_GetTime(FPDF_SIGNATURE signature, char *buffer, unsigned long length)
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFSignatureObj_GetReason(FPDF_SIGNATURE signature, void *buffer, unsigned long length)
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFSignatureObj_GetByteRange(FPDF_SIGNATURE signature, int *buffer, unsigned long length)
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFSignatureObj_GetContents(FPDF_SIGNATURE signature, void *buffer, unsigned long length)
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFSignatureObj_GetSubFilter(FPDF_SIGNATURE signature, char *buffer, unsigned long length)