-
Notifications
You must be signed in to change notification settings - Fork 2
/
base64p.pli
121 lines (94 loc) · 3.24 KB
/
base64p.pli
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
/*
* (C) Copyright IBM Corp. 2021
*/
base64: package;
/*
* ------------------------------------------------------------------
* External Base64 encoding routine
* ------------------------------------------------------------------
*/
dcl base64Encode entry ( *
, fixed binary(32) unsigned
, char(*)
, fixed binary(32) unsigned
)
external ( 'BASE64E' )
returns ( fixed binary(31) signed byvalue )
options ( nodescriptor );
/*
* ------------------------------------------------------------------
* External Base64 decoding routine
* ------------------------------------------------------------------
*/
dcl base64Decode entry ( char(*)
, fixed binary(32) unsigned
, *
, fixed binary(32) unsigned
)
external ( 'BASE64D' )
returns ( fixed binary(31) signed byvalue )
options ( nodescriptor );
/*
* ------------------------------------------------------------------
* Main entry to this PL/I program
* ------------------------------------------------------------------
*/
BASE64P: procedure ( InputParm )
options ( main, noexecops );
/* Main program arguments */
dcl InputParm char(*) var;
/* This application uses SYSPRINT to report status */
dcl SYSPRINT print;
/* Input buffer */
dcl inputData char(100);
/* Output buffer and length */
dcl outputData char(100);
dcl outputLength fixed binary(32) unsigned;
/* Length after encoding */
dcl encodedLength fixed binary(32) unsigned;
/* Return code of this program */
dcl rc fixed binary(31,0) init(0);
/* Text to encode */
dcl plaintext char(26) static init('abcdefghijklmnopqrstuvwxyz');
/* Setup data buffers */
inputData = plaintext;
outputData = '';
outputLength = size(outputData);
/* Encode data in Base64 */
rc = base64Encode(inputData,
size(plaintext),
outputData,
outputLength);
/* Display the results */
put file(SYSPRINT) skip list('Return code : ' || rc);
put file(SYSPRINT) skip list('Output length : ' || outputLength);
put file(SYSPRINT) skip list('Base64 : ' || outputData);
put file(SYSPRINT) skip list('');
/* Exit early if bad rc */
if rc <> 0 then go to base64End;
/* Setup data buffers */
inputData = '';
inputData = SUBSTR(outputData,1,outputLength);
encodedLength = outputLength;
outputData = '';
outputLength = size(outputData);
/* Decode data from Base64 */
rc = base64Decode(inputData,
encodedLength,
outputData,
outputLength);
/* Display the results */
put file(SYSPRINT) skip list('Return code : ' || rc);
put file(SYSPRINT) skip list('Output length : ' || outputLength);
put file(SYSPRINT) skip list('Plaintext : ' || outputData);
base64End:
/* All complete */
call pliretc(rc);
return;
/*
* ------------------------------------------------------------------
* End of main procedure
* ------------------------------------------------------------------
*/
end BASE64P;
end base64;