summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/oberdiek/pdfcrypt.sty
blob: 192c27df3d2a9665245cbdad7f692c0627b45319 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
%%
%% This is file `pdfcrypt.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% pdfcrypt.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Project: pdfcrypt
%% Version: 2016/05/16 v1.1
%% 
%% Copyright (C)
%%    2001, 2006, 2007 Heiko Oberdiek
%%    2016-2019 Oberdiek Package Support Group
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3c of this license or (at your option) any later
%% version. This version of this license is in
%%    https://www.latex-project.org/lppl/lppl-1-3c.txt
%% and the latest version of this license is in
%%    https://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of
%% LaTeX version 2005/12/01 or later.
%% 
%% This work has the LPPL maintenance status "maintained".
%% 
%% The Current Maintainers of this work are
%% Heiko Oberdiek and the Oberdiek Package Support Group
%% https://github.com/ho-tex/oberdiek/issues
%% 
%% 
%% The Base Interpreter refers to any `TeX-Format',
%% because some files are installed in TDS:tex/generic//.
%% 
%% This work consists of the main source file pdfcrypt.dtx
%% and the derived files
%%    pdfcrypt.sty, pdfcrypt.pdf, pdfcrypt.ins, pdfcrypt.drv.
%% 
\expandafter\edef\csname pc@endinput\endcsname{%
  \catcode`\noexpand\@=\the\catcode`\@\relax
  \noexpand\endinput
}
\catcode`\@=11 %

\expandafter\ifx\csname @firstoftwo\endcsname\relax
  \long\def\@firstoftwo#1#2{#1}%
\fi

\expandafter\ifx\csname @secondoftwo\endcsname\relax
  \long\def\@secondoftwo#1#2{#2}%
\fi

\expandafter\ifx\csname @ifundefined\endcsname\relax
  \def\@ifundefined#1{%
    \expandafter\ifx\csname #1\endcsname\relax
      \expandafter\@firstoftwo
    \else
      \expandafter\@secondoftwo
    \fi
  }%
\fi

\@ifundefined{@ifnextchar}{%
  \long\def\@ifnextchar#1#2#3{%
    \let\reserved@d=#1%
    \def\reserved@a{#2}%
    \def\reserved@b{#3}%
    \futurelet\@let@token\@ifnch
  }%
  \def\@ifnch{%
    \ifx\@let@token\@sptoken
      \let\reserved@c\@xifnch
    \else
      \ifx\@let@token\reserved@d
        \let\reserved@c\reserved@a
      \else
        \let\reserved@c\reserved@b
      \fi
    \fi
    \reserved@c
  }%
  \begingroup
    \def\:{\global\let\@sptoken= }%
    \: %
    \def\:{\@xifnch}%
    \expandafter\gdef\: {\futurelet\@let@token\@ifnch}%
  \endgroup
}{}

\@ifundefined{ProvidesPackage}{%
  \def\ProvidesPackage#1{%
    \@ifnextchar[{\pc@ProvidesPackage{#1}}%
                 {\pc@ProvidesPackage{#1}[]}%
  }%
  \def\pc@ProvidesPackage#1[#2]{%
    \immediate\write-1{Package: #1 #2}%
  }%
}{}

\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname RequirePackage\endcsname\relax
  \input infwarerr.sty\relax
\else
  \RequirePackage{infwarerr}%
\fi

\@ifundefined{@gobble}{%
  \long\def\@gobble#1{}%
}{}

\@ifundefined{@empty}{%
  \def\@empty{}%
}{}
\ProvidesPackage{pdfcrypt}%
  [2016/05/16 v1.1 Allows the setting of PDF encryption (HO)]%
\@ifundefined{pdfcryptsetup}{%
  \let\pdfcryptsetup\@gobble
}{%
  \@PackageWarningNoLine{pdfcrypt}{Package pdfcrypt is already loaded}%
  \pc@endinput
}
\newif\ifpc@nopdfcrypt
\ifx Y\nopdfcrypt
  \@PackageWarningNoLine{pdfcrypt}{%
    Encryption disabled by \string \nopdfcrypt\space request%
  }%
  \global\pc@nopdfcrypttrue
\fi
\let\pc@driver\@empty
\begingroup
  % pdfTeX detection
  \@ifundefined{pdfoutput}{%
  }{%
    \ifcase\pdfoutput
    \else
      \@ifundefined{pdfcrypt}{%
        \@PackageError{pdfcrypt}{%
          PDF encryption is not supported with this pdfTeX%
        }{%
          Encryption support was added in 0.14h (2001/03/10)\MessageBreak
          and removed in 1.10a (2003/01/16).%
        }%
        \endgroup
        \pc@endinput
      }{%
        \gdef\pc@driver{pdftex}%
      }%
    \fi
  }%
  % VTeX detection
  \@ifundefined{OpMode}{%
  }{%
    \ifnum\OpMode=1 %
      \ifnum\@ifundefined{VTeXversion}0\VTeXversion<735 %
        \@PackageError{pdfcrypt}{%
          PDF encryption is not supported with this VTeX%
        }{%
          You need VTeX 7.35 or higher.%
        }%
        \endgroup
        \pc@endinput
      \else
        \gdef\pc@driver{vtex}%
      \fi
    \fi
  }%
\endgroup
\@ifundefined{@makeother}{%
  \def\@makeother#1{\catcode`#1=12\relax}%
}{}

\@ifundefined{g@addto@macro}{%
  \long\def\g@addto@macro#1#2{%
    \begingroup
      \toks@\expandafter{#1#2}%
      \xdef#1{\the\toks@}%
    \endgroup
  }%
}{}

\@ifundefined{@namedef}{%
  \def\@namedef#1{\expandafter\def\csname#1\endcsname}%
}{}

\@ifundefined{@nameuse}{%
  \def\@nameuse#1{\csname #1\endcsname}%
}{}

\def\pc@KeyvalRestore{%
  \let\pc@KeyvalRestore\@undefined
}

\let\pcOrg@NeedsTeXFormat\NeedsTeXFormat
\@ifundefined{NeedsTeXFormat}{%
  \def\NeedsTeXFormat#1{}%
  \g@addto@macro\pc@KeyvalRestore{%
    \let\NeedsTeXFormat\pcOrg@NeedsTeXFormat
  }%
}{}

\let\pcOrg@DeclareOption\DeclareOption
\@ifundefined{DeclareOption}{%
  \def\DeclareOption#1#2{#2}%
  \g@addto@macro\pc@KeyvalRestore{%
    \let\DeclareOption\pcOrg@DeclareOption
  }%
}{}

\let\pcOrg@ExecuteOptions\ExecuteOptions
\@ifundefined{ExecuteOptions}{%
  \def\ExecuteOptions#1{}%
  \g@addto@macro\pc@KeyvalRestore{%
    \let\ExecuteOptions\pcOrg@ExecuteOptions
  }%
}{}

\let\pcOrg@ProcessOptions\ProcessOptions
\@ifundefined{ProcessOptions}{%
  \def\ProcessOptions{}%
  \g@addto@macro\pc@KeyvalRestore{%
    \let\ProcessOptions\pcOrg@ProcessOptions
  }%
}{}%

\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname RequirePackage\endcsname\relax
  \input keyval.sty\relax
\else
  \RequirePackage{keyval}%
\fi
\pc@KeyvalRestore
\@ifundefined{@dblarg}{%
  \long\def\@dblarg#1{\@ifnextchar[{#1}{\@xdblarg{#1}}}%
  \long\def\@xdblarg#1#2{#1[{#2}]{#2}}%
}{}

\newif\ifpc@set
\newif\ifpc@print
\newif\ifpc@copy
\newif\ifpc@edit
\newif\ifpc@annotate
\newif\ifpc@debug
\let\pc@owner\@empty
\let\pc@user\@empty

\pc@printtrue
\pc@copytrue
\pc@edittrue
\pc@annotatetrue

\edef\pc@temp{\catcode`\noexpand\"=\the\catcode`\"\relax}
\@makeother\"
\def\pc@set{%
  \@PackageInfo{pdfcrypt}{%
    \ifpc@debug
      \ifx\pc@owner\@empty
        No owner password%
      \else
        Owner password: `\pc@owner'%
      \fi
      \MessageBreak
      \ifx\pc@user\@empty
        No user password%
      \else
        User password: `\pc@user'%
      \fi
      \MessageBreak
      Flags: %
      \ifpc@print   \else no\fi print, %
      \ifpc@copy    \else no\fi copy, %
      \ifpc@edit    \else no\fi edit, %
      \ifpc@annotate\else no\fi annotate%
      \MessageBreak
    \fi
    \ifpc@nopdfcrypt
      Encryption is disabled by `\string\nopdfcrypt'%
    \else
      Encryption is set for `\pc@driver'%
    \fi
  }%
  \ifpc@nopdfcrypt
  \else
    \@ifundefined{pc@set@\pc@driver}{%
      \ifx\pc@driver\@empty
        \@PackageError{pdfcrypt}{No driver for encryption %
          support found}\@ehc
      \else
        \@PackageError{pdfcrypt}{Cannot set encryption for %
          unknown driver `\pc@driver'}\@ehc
      \fi
    }{%
      \@nameuse{pc@set@\pc@driver}%
    }%
  \fi
}
\def\pc@set@pdftex{%
  \ifnum\pdftexversion<100 %
    \pc@set@pdftexold
  \else
    \pc@set@pdftexnew
  \fi
}
\def\pc@set@pdftexold{%
  \pdfcrypt{%
    owner "\pc@owner" %
    user "\pc@user" %
    \ifpc@print   \else no\fi print %
    \ifpc@copy    \else no\fi copy %
    \ifpc@edit    \else no\fi edit %
    \ifpc@annotate\else no\fi annotate%
  }%
}
\def\pc@set@pdftexnew{%
  \pdfcrypt
    owner{\pc@owner}%
    user{\pc@user}%
    \ifpc@print   \else no\fi print %
    \ifpc@copy    \else no\fi copy %
    \ifpc@edit    \else no\fi edit %
    \ifpc@annotate\else no\fi annotate%
  \relax
}
\def\pc@set@vtex{%
  \immediate\special{!security %
    O=\pc@MakeVTeXString\pc@owner,%
    U=\pc@MakeVTeXString\pc@user,%
    P\ifpc@print +\else -\fi,%
    C\ifpc@copy +\else -\fi,%
    M\ifpc@edit +\else -\fi,%
    A\ifpc@annotate +\else -\fi
  }%
}
\def\pc@MakeVTeXString#1{%
  "\expandafter\pc@@MakeVTeXString#1"\@nil"%
}
\def\pc@@MakeVTeXString#1"#2\@nil{%
  #1%
  \ifx\\#2\\%
  \else
    ""%
    \@ReturnAfterFi{%
      \pc@@MakeVTeXString#2\@nil
    }%
  \fi
}
\long\def\@ReturnAfterFi#1\fi{\fi#1}
\pc@temp

\begingroup
  \catcode`\ =12 \gdef\pc@spaceother{ }\catcode`\ =10\relax
  \catcode`\|=0 %
  \catcode`\\=12 %
  |gdef|pc@DefString#1#2{%
    |def#1{#2}%
    |edef#1{|expandafter|strip@prefix|meaning#1}%
    |edef#1{|expandafter|pc@SpaceToOther#1 |@nil}%
    |edef#1{|expandafter|pc@EscapeRemove#1|@empty\|@empty|@nil}%
  }%
  |gdef|pc@EscapeRemove#1\#2#3|@nil{%
    #1#2%
    |ifx|\#3|\%%
    |else
      |@ReturnAfterFi{%
        |pc@EscapeRemove#3|@nil
      }%
    |fi
  }%
|endgroup
\def\pc@SpaceToOther#1 #2\@nil{%
  #1%
  \ifx\\#2\\%
  \else
    \pc@spaceother
    \@ReturnAfterFi{%
      \pc@SpaceToOther#2\@nil
    }%
  \fi
}

\def\pc@boolkey{\@dblarg\pc@@boolkey}
\def\pc@@boolkey[#1]#2#3{%
  \lowercase{\def\pc@temp{#3}}%
  \ifx\pc@temp\@empty
    \let\pc@temp\pc@true
  \fi
  \ifx\pc@temp\pc@true
  \else
    \ifx\pc@temp\pc@false
    \else
      \let\pc@temp\relax
    \fi
  \fi
  \ifx\pc@temp\relax
    \@PackageWarning{pdfcrypt}{%
      Unexpected value \string`#3\string' of %
      option \string`#2\string'\MessageBreak
      instead of %
      \string`true\string' or \string`false\string'%
    }%
  \else
    \csname pc@#2\pc@temp\endcsname
  \fi
}
\def\pc@true{true}
\def\pc@false{false}

\define@key{pc}{set}[true]{%
  \pc@boolkey{set}{#1}%
}
\define@key{pc}{pdftex}[]{%
  \def\pc@driver{pdftex}%
}
\define@key{pc}{vtex}[]{%
  \def\pc@driver{vtex}%
}
\define@key{pc}{print}[true]{%
  \pc@boolkey{print}{#1}%
}
\define@key{pc}{copy}[true]{%
  \pc@boolkey{copy}{#1}%
}
\define@key{pc}{edit}[true]{%
  \pc@boolkey{edit}{#1}%
}
\define@key{pc}{annotate}[true]{%
  \pc@boolkey{annotate}{#1}%
}
\define@key{pc}{all}[]{%
  \pc@boolkey{print}{true}%
  \pc@boolkey{copy}{true}%
  \pc@boolkey{edit}{true}%
  \pc@boolkey{annotate}{true}%
}
\define@key{pc}{none}[]{%
  \pc@boolkey{print}{false}%
  \pc@boolkey{copy}{false}%
  \pc@boolkey{edit}{false}%
  \pc@boolkey{annotate}{false}%
}

\define@key{pc}{owner}{%
  \pc@DefString\pc@owner{#1}%
}
\define@key{pc}{user}{%
  \pc@DefString\pc@user{#1}%
}
\define@key{pc}{debug}[true]{%
  \pc@boolkey{debug}{#1}%
}

\def\pdfcryptsetup#1{%
  \setkeys{pc}{#1}%
  \ifpc@set
    \pc@set
    \global\let\pc@set\relax
    \gdef\pdfcryptsetup##1{%
      \@PackageWarning{pdfcrypt}{%
        Encryption options are already set\MessageBreak
        new values are ignored%
      }%
    }%
  \fi
}
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname @onlypreamble\endcsname\relax
\else
  \@onlypreamble\pdfcryptsetup
\fi
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname InputIfFileExists\endcsname\relax
  \@PackageInfo{pdfcrypt}{%
    Configuration file pdfcrypt.cfg not supported.%
  }%
\else
  \let\pc@ExecuteOptions\ExecuteOptions
  \InputIfFileExists{pdfcrypt.cfg}{}{}%
  \let\ExecuteOptions\pc@ExecuteOptions
\fi
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname @classoptionslist\endcsname\relax
  \expandafter\pc@endinput
\fi
\def\pc@ProcessOptionsWithKV{%
  \let\pc@temp\@empty
  \@for\CurrentOption:=\@classoptionslist\do{%
    \@ifundefined{KV@pc@\CurrentOption}{}{%
      \edef\pc@temp{\pc@temp,\CurrentOption,}%
      \@expandtwoargs\@removeelement\CurrentOption
        \@unusedoptionlist\@unusedoptionlist
    }%
  }%
  \edef\pc@temp{%
    \noexpand\pdfcryptsetup{%
      \pc@temp\@ptionlist{\@currname.\@currext}%
    }%
  }%
  \pc@temp
}
\pc@ProcessOptionsWithKV
\AtEndOfPackage{\let\@unprocessedoptions\relax}
\AtBeginDocument{\pc@set}

\pc@endinput
\endinput
%%
%% End of file `pdfcrypt.sty'.