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/compiler_specific.h"
15#include "core/fxcrt/fx_memcpy_wrappers.h"
16#include "core/fxcrt/numerics/safe_conversions.h"
17#include "core/fxcrt/span.h"
18#include "core/fxcrt/span_util.h"
19#include "core/fxcrt/stl_util.h"
20#include "fpdfsdk/cpdfsdk_helpers.h"
24std::vector<RetainPtr<
const CPDF_Dictionary>> CollectSignatures(
26 std::vector<RetainPtr<
const CPDF_Dictionary>> signatures;
40 for (
auto& field : locker) {
41 RetainPtr<
const CPDF_Dictionary> field_dict = field->GetDict();
42 if (field_dict && field_dict->GetNameFor(pdfium::form_fields::kFT) ==
43 pdfium::form_fields::kSig) {
44 signatures.push_back(std::move(field_dict));
57 return fxcrt::CollectionSize<
int>(CollectSignatures(doc));
66 std::vector<RetainPtr<
const CPDF_Dictionary>> signatures =
67 CollectSignatures(doc);
68 if (!
fxcrt::IndexInBounds(signatures, index))
71 return FPDFSignatureFromCPDFDictionary(signatures[index].Get());
77 unsigned long length) {
80 if (!signature_dict) {
84 signature_dict->GetDictFor(pdfium::form_fields::kV);
89 auto result_span =
UNSAFE_BUFFERS(SpanFromFPDFApiArgs(buffer, length));
90 ByteString contents = value_dict->GetByteStringFor(
"Contents");
91 fxcrt::try_spancpy(result_span, contents.span());
92 return pdfium::checked_cast<
unsigned long>(contents.span().size());
98 unsigned long length) {
105 signature_dict->GetDictFor(pdfium::form_fields::kV);
113 const unsigned long byte_range_len =
114 fxcrt::CollectionSize<
unsigned long>(*byte_range);
115 if (buffer && length >= byte_range_len) {
118 for (size_t i = 0; i < byte_range_len; ++i) {
119 buffer_span[i] = byte_range->GetIntegerAt(i);
122 return byte_range_len;
128 unsigned long length) {
135 signature_dict->GetDictFor(pdfium::form_fields::kV);
136 if (!value_dict || !value_dict->KeyExist(
"SubFilter"))
139 ByteString sub_filter = value_dict->GetNameFor(
"SubFilter");
142 return NulTerminateMaybeCopyAndReturnLength(
149 unsigned long length) {
156 signature_dict->GetDictFor(pdfium::form_fields::kV);
161 if (!obj || !obj->IsString())
165 return Utf16EncodeMaybeCopyAndReturnLength(
166 obj->GetUnicodeText(),
173 unsigned long length) {
180 signature_dict->GetDictFor(pdfium::form_fields::kV);
185 if (!obj || !obj->IsString())
189 return NulTerminateMaybeCopyAndReturnLength(
190 obj->GetString(),
UNSAFE_BUFFERS(SpanFromFPDFApiArgs(buffer, length)));
202 signature_dict->GetDictFor(pdfium::form_fields::kV);
211 for (
auto& reference : locker) {
212 RetainPtr<
const CPDF_Dictionary> reference_dict = reference->GetDict();
216 ByteString transform_method = reference_dict->GetNameFor(
"TransformMethod");
217 if (transform_method !=
"DocMDP")
220 RetainPtr<
const CPDF_Dictionary> transform_params =
221 reference_dict->GetDictFor(
"TransformParams");
222 if (!transform_params)
226 permission = transform_params->GetIntegerFor(
"P", 2);
227 if (permission < 1 || permission > 3)
fxcrt::ByteString ByteString
std::vector< RetainPtr< CPDF_Object > >::const_iterator const_iterator
std::map< ByteString, RetainPtr< CPDF_Object >, std::less<> > DictMap
const CPDF_Dictionary * GetRoot() const
#define UNSAFE_BUFFERS(...)
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)