Last active
September 28, 2018 15:42
-
-
Save ArTourter/a0f464b9018bd74fe1a5fce2800784ef to your computer and use it in GitHub Desktop.
Arara yaml rule to encrypt pdf output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!config | |
identifier: encrypt | |
name: Encrypt | |
authors: | |
- Greg Tourte | |
- Paulo Cereda | |
commands: | |
- name: The Encryption tool | |
command: > | |
@{ | |
input = getBasename(file).concat('.pdf'); | |
output = getBasename(file).concat('_enc.pdf'); | |
encryption = []; | |
list = []; | |
list.add('qpdf'); | |
list.add('--encrypt'); | |
list.add(userpwd); | |
list.add(ownerpwd); | |
list.add(keylength); | |
if (isNotEmpty(extract)) { | |
list.add(extract); | |
} | |
if (isNotEmpty(annotate)) { | |
list.add(annotate); | |
} | |
if (isNotEmpty(modify)) { | |
list.add(modify); | |
} | |
if (isNotEmpty(print)) { | |
list.add(print); | |
} | |
if (isNotEmpty(accessibility)) { | |
list.add(accessibility); | |
} | |
if (isNotEmpty(useaes)) { | |
list.add(useaes); | |
} | |
if (isNotEmpty(clearmeta)) { | |
list.add(clearmeta); | |
} | |
list.add('--'); | |
if (isNotEmpty(optimize)) { | |
list.add(optimize); | |
} | |
list.add(input); | |
list.add(output); | |
encryption.add(getCommand(list)); | |
if ( isNotEmpty(overwrite) && isTrue(overwrite) ) { | |
encryption.add( getCommand('mv', output, input) ); | |
} | |
return encryption; | |
} | |
# | |
arguments: | |
- identifier: userpwd | |
flag: > | |
@{ | |
parameters.userpwd | |
} | |
required: true | |
- identifier: ownerpwd | |
flag: > | |
@{ | |
return parameters.ownerpwd; | |
} | |
required: true | |
- identifier: keylength | |
flag: > | |
@{ | |
if (['40', '128', '256'].contains(parameters.keylength)) { | |
if ( parameters.keylength == '40' ) { | |
System.out.println( "*WARNING* Encryption key length is very weak. You document will not be secure" ); | |
} | |
return parameters.keylength; | |
} | |
else { | |
throwError( 'The provided keylength value is not valid. keylength may be 40, 128 or 256.' ); | |
} | |
} | |
required: true | |
- identifier: extract | |
flag: > | |
@{ | |
isTrue( parameters.extract, '--extract=y', '--extract=n' ); | |
} | |
# modify options differs depending on the key length used: | |
# it is a simple y/n for a 40bit key, and | |
# all/annotate/form/assemble/none for 128bit and above. | |
# you should be able to give more than one option. | |
- identifier: modify | |
flag: > | |
@{ | |
if ( parameters.keylength == '40' ) { | |
isTrue(parameters.modify, '--modify=y', '--modify=n'); | |
} else if ( ([ '128', '256']).contains(parameters.keylength) ) { | |
if ( !(['all', 'annotate', 'form', 'assemble', 'none']).contains(parameters.modify) ) { | |
System.out.println( 'The "modify" option must only be one of "full", "annotate", "form", "assemble", or "none" for 128bit or 256bit keys' ); | |
} | |
return '--modify='.concat(parameters.modify); | |
} | |
} | |
# print options differs depending on the key length used: | |
# it is a simple y/n for a 40bit key, and | |
# full/low/none for 128bit and above. | |
- identifier: print | |
flag: > | |
@{ | |
if ( parameters.keylength == '40' ) { | |
isTrue(parameters.print, '--print=y', '--print=n'); | |
} else if (([ '128', '256']).contains(parameters.keylength)) { | |
if ( !(['full', 'low', 'none']).contains(parameters.print) ) { | |
System.out.println( 'The "print" option must only be one of "full", "low", or "none" for 128bit or 256bit keys' ); | |
} | |
return '--print='.concat(parameters.print); | |
} | |
} | |
# Only valid for 40bit keys | |
- identifier: annotate | |
flag: > | |
@{ | |
if ( parameters.keylength == '40' ) { | |
isTrue( parameters.annotate, '--annotate=y', '--annotate=n' ); | |
} else { | |
System.out.println( 'The "annotate" option is only valid for a 40bit key' ); | |
isTrue( parameters.annotate, '--annotate=y', '--annotate=n' ); | |
} | |
} | |
# This option is only available with a keylength of 128bit or above | |
- identifier: accessibility | |
flag: > | |
@{ | |
if ( parameters.keylength == '40' ) { | |
System.out.println( 'The "accessibility" option is not valid for a key length of 40' ); | |
} | |
isTrue( parameters.accessibility, '--accessibility=y', '--accessibility=n' ); | |
} | |
# This option is only available with a keylength of 128bit or above | |
- identifier: clearmeta | |
flag: > | |
@{ | |
if ( parameters.keylength == '40' ) { | |
System.out.println( 'The "clearmeta" option is not valid for a key length of 40' ); | |
} | |
isTrue( parameters.clearmeta, '--cleartext-metadata' ); | |
} | |
# | |
- identifier: useaes | |
flag: > | |
@{ | |
if ( parameters.keylength == '40' ) { | |
System.out.println( 'The "useaes" option is not valid for a 40bit key' ); | |
} else if ( parameters.keylength == '256' ) { | |
System.out.println( 'The "useaes" option is not valid for a 256bit key. AES is used by default.' ); | |
} else {} | |
isTrue( parameters.useaes, '--use-aes=y', '--use-aes=n' ); | |
} | |
# | |
- identifier: optimize | |
flag: > | |
@{ | |
isTrue( parameters.optimize, '--linearize' ); | |
} | |
# | |
- identifier: overwrite | |
flag: > | |
@{ | |
return parameters.overwrite; | |
} | |
# | |
# vim: ts=2 sw=2 et |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment