Skip to content

Commit 20c4187

Browse files
authoredOct 4, 2024
Merge pull request #38 from luicfrr/patch-1
2 parents d6946b0 + 16fd09d commit 20c4187

File tree

1 file changed

+53
-34
lines changed

1 file changed

+53
-34
lines changed
 

‎src/encrypt.ts

+53-34
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@ const EncryptDefaults = {
55
keyLength: 256,
66
overwrite: true,
77
};
8-
9-
export interface EncryptOptions {
8+
type BaseYesNoOptions = "y" | "n"
9+
type BasePrintOptions = "full" | "low" | "none"
10+
interface BaseEncryptOptions {
11+
/** Optional - Path to custom qpdf binary */
12+
qpdfPath?: string
1013
/** The location of the unencrypted pdf file */
1114
input: string;
12-
/**
13-
* A number which defines the encryption algorithm to be used.
14-
* Using a keyLengh of 40 is insecure.
15-
* @default 256
16-
*/
17-
keyLength?: 40 | 128 | 256;
1815
/** If defined, the output location of the encrypted pdf. If not defined, a Buffer will be returned. */
1916
output?: string;
2017
/**
@@ -27,36 +24,58 @@ export interface EncryptOptions {
2724
* Optionally, an object containing `user` and `owner` for setting different roles.
2825
* If undefined, will encrypt a pdf without requiring a password to decrypt
2926
*/
30-
password?:
31-
| string
32-
| {
33-
owner: string;
34-
user: string;
35-
};
27+
password?: string| {
28+
owner: string;
29+
user: string;
30+
};
31+
}
32+
interface BaseRestrictionsOptions {
33+
/** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-accessibility */
34+
accessibility?: BaseYesNoOptions;
35+
/** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-annotate */
36+
annotate?: BaseYesNoOptions;
37+
/** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-assemble */
38+
assemble?: BaseYesNoOptions;
39+
/** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-cleartext-metadata */
40+
cleartextMetadata?: boolean;
41+
/** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-extract */
42+
extract?: BaseYesNoOptions;
43+
/** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-form */
44+
form?: BaseYesNoOptions;
45+
/** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-modify */
46+
modify?: BaseYesNoOptions | "all" | "annotate" | "form" | "assembly" | "none";
47+
/** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-modify-other */
48+
modifyOther?: BaseYesNoOptions;
49+
/** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-use-aes */
50+
useAes?: BaseYesNoOptions;
51+
}
52+
interface Encrypt40bitOptions extends BaseEncryptOptions {
53+
/**
54+
* A number which defines the encryption algorithm to be used.
55+
* Using a keyLengh of 40 is insecure.
56+
* @default 256
57+
*/
58+
keyLength?: 40
3659
/** Restrictions for the encrypted pdf */
3760
restrictions?: {
38-
/** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-accessibility */
39-
accessibility?: "y" | "n";
40-
/** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-annotate */
41-
annotate?: "y" | "n";
42-
/** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-assemble */
43-
assemble?: "y" | "n";
44-
/** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-cleartext-metadata */
45-
cleartextMetadata?: boolean;
46-
/** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-extract */
47-
extract?: "y" | "n";
48-
/** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-form */
49-
form?: "y" | "n";
50-
/** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-modify */
51-
modify?: "y" | "n" | "all" | "annotate" | "form" | "assembly" | "none";
52-
/** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-modify-other */
53-
modifyOther?: "y" | "n";
5461
/** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-print */
55-
print?: "y" | "n" | "full" | "low" | "none";
56-
/** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-use-aes */
57-
useAes?: "y" | "n";
58-
};
62+
print?: BaseYesNoOptions | BasePrintOptions;
63+
} & BaseRestrictionsOptions;
64+
}
65+
interface EncryptDefaultOptions extends BaseEncryptOptions {
66+
/**
67+
* A number which defines the encryption algorithm to be used.
68+
* Using a keyLengh of 40 is insecure.
69+
* @default 256
70+
*/
71+
keyLength?: 128 | 256;
72+
/** Restrictions for the encrypted pdf */
73+
restrictions?: {
74+
/** Please see: https://qpdf.readthedocs.io/en/stable/cli.html#option-print */
75+
print?: BasePrintOptions;
76+
} & BaseRestrictionsOptions;
5977
}
78+
export type EncryptOptions = Encrypt40bitOptions | EncryptDefaultOptions
6079

6180
/**
6281
* Encrypts a PDF file

0 commit comments

Comments
 (0)