{ This program demonstrates use of the VAX/VMS Condition Handling } { Facility to prevent the INVWEAK_KEY error from terminating an } { image. } { } { To use this example, issue the following commands: } { PASCAL ENCRYPT$EXAMPLES:ENCRYPT_STRUCTURES/ENVIRONMENT } { PASCAL ENCRYPT$EXAMPLES:ENCRYPT_MESSAGES/ENVIRONMENT } { PASCAL SAMPLE_HANDLER } { LINK SAMPLE_HANDLER } { ENCRYPT/CREATE_KEY TESTKEY 1F1F1F1F0E0E0E0E/HEX ! Weak key } { RUN SAMPLE } [INHERIT( 'ENCRYPT_STRUCTURES.PEN', {See VAX Pascal reference for} 'ENCRYPT_MESSAGES.PEN', {information on Environment Files} 'SYS$LIBRARY:STARLET.PEN' )] PROGRAM Sample_Handler (input,output); CONST inFile = 'ENCRYPT$EXAMPLES:SAMPLE_HANDLER.PAS'; { name of input file } outFile = 'SAMPLE_HANDLER.OUT'; { name of output file } key = 'TESTKEY'; { name of key } TYPE string = PACKED ARRAY [1..80] OF CHAR; sigarr = ARRAY [0..9] OF UNSIGNED; { Signal arguments } mecharr = ARRAY [0..4] OF UNSIGNED; { Mechanism args } VAR status: UNSIGNED; { Return status from external calls } {---------------------------------------------------------------------} { This declaration borrowed from ENCRYPT$EXAMPLES:ENCRYPT_DEF.PAS } { Note that optional parameter item_list is not used here. } [ASYNCHRONOUS] FUNCTION encrypt$encrypt_file ( input_file : [CLASS_S] PACKED ARRAY [$l1..$u1:INTEGER] OF CHAR; output_file : [CLASS_S] PACKED ARRAY [$l2..$u2:INTEGER] OF CHAR; key_name : [CLASS_S] PACKED ARRAY [$l3..$u3:INTEGER] OF CHAR; algorithm : [CLASS_S] PACKED ARRAY [$l4..$u4:INTEGER] OF CHAR; file_flags : UNSIGNED) : INTEGER; EXTERNAL; {---------------------------------------------------------------------} { See the VMS RTL Library (LIB$) Manual for LIB$SIG_TO_RET } [ASYNCHRONOUS] FUNCTION LIB$SIG_TO_RET (sigargs: sigarr; mechargs: mecharr): UNSIGNED; EXTERN; {---------------------------------------------------------------------} { This condition handler protects from image termination due } { to use of a weak key to encrypt a file. } [ASYNCHRONOUS] FUNCTION CondHandler (VAR sigargs: sigarr; VAR mechargs: mecharr): UNSIGNED; BEGIN IF (sigargs[1] = encrypt$_invweak_key) { If weak key error} THEN LIB$SIG_TO_RET(sigargs,mechargs); { then quit } CondHandler := ss$_resignal; { Otherwise pass signal up } END; {---------------------------------------------------------------------} { Perform the file encryption operation } FUNCTION DoIt: UNSIGNED; VAR status: UNSIGNED; { Local status from external calls } flags: UNSIGNED; { Flags to tell VAX Encryption what to do } BEGIN ESTABLISH (CondHandler); { Identify condition handler to VMS } flags := Encrypt$M_File_Encrypt; { Prepare for file encryption } status := Encrypt$Encrypt_File { Perform the operation } (%STDESCR inFile, %STDESCR outFile, %STDESCR key, %STDESCR 'DESCBC',flags); DoIt := status; { Return status to caller } END; {---------------------------------------------------------------------} BEGIN status := DoIt; { Encrypt the file } IF (status <> ss$_normal) { Inform user of success or failure } THEN WRITE('Could not encrypt file; status is ',status) ELSE WRITE('File encrypted successfully'); END.