Skip to content

Commit 74bc6d2

Browse files
authored
Merge pull request #14189 from janekotovich/security_handler
[api-minor] Implement securityHandler in the scripting API (bug 1731578)
2 parents f40bbe8 + 91fc643 commit 74bc6d2

File tree

7 files changed

+32
-1
lines changed

7 files changed

+32
-1
lines changed

src/core/crypto.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,7 @@ const CipherTransformFactory = (function CipherTransformFactoryClosure() {
16891689
if (!isName(filter, "Standard")) {
16901690
throw new FormatError("unknown encryption method");
16911691
}
1692+
this.filterName = filter.name;
16921693
this.dict = dict;
16931694
const algorithm = dict.get("V");
16941695
if (

src/core/document.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,9 @@ class PDFDocument {
11611161
const docInfo = {
11621162
PDFFormatVersion: version,
11631163
Language: this.catalog.lang,
1164+
EncryptFilterName: this.xref.encrypt
1165+
? this.xref.encrypt.filterName
1166+
: null,
11641167
IsLinearized: !!this.linearization,
11651168
IsAcroFormPresent: this.formInfo.hasAcroForm,
11661169
IsXFAPresent: this.formInfo.hasXfa,

src/scripting_api/doc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class Doc extends PDFObject {
6666
this._numPages = data.numPages || 1;
6767
this._pageNum = data.pageNum || 0;
6868
this._producer = data.Producer || "";
69+
this._securityHandler = data.EncryptFilterName || null;
6970
this._subject = data.Subject || "";
7071
this._title = data.Title || "";
7172
this._URL = data.URL || "";
@@ -522,7 +523,7 @@ class Doc extends PDFObject {
522523
}
523524

524525
get securityHandler() {
525-
return null;
526+
return this._securityHandler;
526527
}
527528

528529
set securityHandler(_) {

test/integration/scripting_spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,4 +896,26 @@ describe("Interaction", () => {
896896
);
897897
});
898898
});
899+
900+
describe("in secHandler.pdf", () => {
901+
let pages;
902+
903+
beforeAll(async () => {
904+
pages = await loadAndWait("secHandler.pdf", "#\\32 5R");
905+
});
906+
907+
afterAll(async () => {
908+
await closePages(pages);
909+
});
910+
it("must print securityHandler value in a text field", async () => {
911+
await Promise.all(
912+
pages.map(async ([browserName, page]) => {
913+
const text = await actAndWaitForInput(page, "#\\32 5R", async () => {
914+
await page.click("[data-annotation-id='26R']");
915+
});
916+
expect(text).withContext(`In ${browserName}`).toEqual("Standard");
917+
})
918+
);
919+
});
920+
});
899921
});

test/pdfs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,3 +477,4 @@
477477
!issue12337.pdf
478478
!pr12564.pdf
479479
!pr12828.pdf
480+
!secHandler.pdf

test/pdfs/secHandler.pdf

7.62 KB
Binary file not shown.

test/unit/api_spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,7 @@ describe("api", function () {
11661166
// The following are PDF.js specific, non-standard, properties.
11671167
expect(info.PDFFormatVersion).toEqual("1.7");
11681168
expect(info.Language).toEqual("en");
1169+
expect(info.EncryptFilterName).toEqual(null);
11691170
expect(info.IsLinearized).toEqual(false);
11701171
expect(info.IsAcroFormPresent).toEqual(false);
11711172
expect(info.IsXFAPresent).toEqual(false);
@@ -1201,6 +1202,7 @@ describe("api", function () {
12011202
// The following are PDF.js specific, non-standard, properties.
12021203
expect(info.PDFFormatVersion).toEqual("1.4");
12031204
expect(info.Language).toEqual(null);
1205+
expect(info.EncryptFilterName).toEqual(null);
12041206
expect(info.IsLinearized).toEqual(false);
12051207
expect(info.IsAcroFormPresent).toEqual(false);
12061208
expect(info.IsXFAPresent).toEqual(false);
@@ -1223,6 +1225,7 @@ describe("api", function () {
12231225
// The following are PDF.js specific, non-standard, properties.
12241226
expect(info.PDFFormatVersion).toEqual(null);
12251227
expect(info.Language).toEqual(null);
1228+
expect(info.EncryptFilterName).toEqual(null);
12261229
expect(info.IsLinearized).toEqual(false);
12271230
expect(info.IsAcroFormPresent).toEqual(false);
12281231
expect(info.IsXFAPresent).toEqual(false);

0 commit comments

Comments
 (0)