Skip to content

[api-minor] Implement securityHandler in the scripting API (bug 1731578) #14189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/core/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -1689,6 +1689,7 @@ const CipherTransformFactory = (function CipherTransformFactoryClosure() {
if (!isName(filter, "Standard")) {
throw new FormatError("unknown encryption method");
}
this.filterName = filter.name;
this.dict = dict;
const algorithm = dict.get("V");
if (
Expand Down
3 changes: 3 additions & 0 deletions src/core/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,9 @@ class PDFDocument {
const docInfo = {
PDFFormatVersion: version,
Language: this.catalog.lang,
EncryptFilterName: this.xref.encrypt
? this.xref.encrypt.filterName
: null,
IsLinearized: !!this.linearization,
IsAcroFormPresent: this.formInfo.hasAcroForm,
IsXFAPresent: this.formInfo.hasXfa,
Expand Down
3 changes: 2 additions & 1 deletion src/scripting_api/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Doc extends PDFObject {
this._numPages = data.numPages || 1;
this._pageNum = data.pageNum || 0;
this._producer = data.Producer || "";
this._securityHandler = data.EncryptFilterName || null;
this._subject = data.Subject || "";
this._title = data.Title || "";
this._URL = data.URL || "";
Expand Down Expand Up @@ -522,7 +523,7 @@ class Doc extends PDFObject {
}

get securityHandler() {
return null;
return this._securityHandler;
}

set securityHandler(_) {
Expand Down
22 changes: 22 additions & 0 deletions test/integration/scripting_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -896,4 +896,26 @@ describe("Interaction", () => {
);
});
});

describe("in secHandler.pdf", () => {
let pages;

beforeAll(async () => {
pages = await loadAndWait("secHandler.pdf", "#\\32 5R");
});

afterAll(async () => {
await closePages(pages);
});
it("must print securityHandler value in a text field", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
const text = await actAndWaitForInput(page, "#\\32 5R", async () => {
await page.click("[data-annotation-id='26R']");
});
expect(text).withContext(`In ${browserName}`).toEqual("Standard");
})
);
});
});
});
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,4 @@
!issue12337.pdf
!pr12564.pdf
!pr12828.pdf
!secHandler.pdf
Binary file added test/pdfs/secHandler.pdf
Binary file not shown.
3 changes: 3 additions & 0 deletions test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,7 @@ describe("api", function () {
// The following are PDF.js specific, non-standard, properties.
expect(info.PDFFormatVersion).toEqual("1.7");
expect(info.Language).toEqual("en");
expect(info.EncryptFilterName).toEqual(null);
expect(info.IsLinearized).toEqual(false);
expect(info.IsAcroFormPresent).toEqual(false);
expect(info.IsXFAPresent).toEqual(false);
Expand Down Expand Up @@ -1201,6 +1202,7 @@ describe("api", function () {
// The following are PDF.js specific, non-standard, properties.
expect(info.PDFFormatVersion).toEqual("1.4");
expect(info.Language).toEqual(null);
expect(info.EncryptFilterName).toEqual(null);
expect(info.IsLinearized).toEqual(false);
expect(info.IsAcroFormPresent).toEqual(false);
expect(info.IsXFAPresent).toEqual(false);
Expand All @@ -1223,6 +1225,7 @@ describe("api", function () {
// The following are PDF.js specific, non-standard, properties.
expect(info.PDFFormatVersion).toEqual(null);
expect(info.Language).toEqual(null);
expect(info.EncryptFilterName).toEqual(null);
expect(info.IsLinearized).toEqual(false);
expect(info.IsAcroFormPresent).toEqual(false);
expect(info.IsXFAPresent).toEqual(false);
Expand Down