-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbase64_conv_tst.sh
executable file
·423 lines (400 loc) · 11.5 KB
/
base64_conv_tst.sh
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
#!/bin/bash
#
# Test script for the base64conv program.
#
# -q for 'quiet' mode.
T=yes
FAILS=0
Q=N
TOTAL=0
if [ x$1 = "x-q" ] ; then Q=Y ; fi
function Base64_Conv_Func {
local out_var=$1;
shift
local ret_str
ret_str=`../run/base64conv 2>/dev/null $*`
((TOTAL++))
eval $out_var=\$ret_str;
}
# simple test cycling through the types. $MEM and $V9 should be same in the end
MEM=123456789aBCDefGHJ
Base64_Conv_Func V1 -i raw -q -e -o hex $MEM
Base64_Conv_Func V2 -i hex -q -e -o mime $V1
Base64_Conv_Func V3 -i mime -q -e -o crypt $V2
Base64_Conv_Func V4 -i crypt -q -e -o cryptBS $V3
Base64_Conv_Func V5 -i cryptBS -q -e -o mime $V4
Base64_Conv_Func V6 -i mime -q -e -o cryptBS $V5
Base64_Conv_Func V7 -i cryptBS -q -e -o crypt $V6
Base64_Conv_Func V8 -i crypt -q -e -o hex $V7
Base64_Conv_Func V9 -i hex -q -e -o raw $V8
if [ x$MEM != x$V9 ];
then
((FAILS++))
echo "Simple test failed. '$MEM' not same as '$V9'"
echo "MEM='$MEM'"
echo "V1 ='$V1'"
echo "V2 ='$V2'"
echo "V3 ='$V3'"
echo "V4 ='$V4'"
echo "V5 ='$V5'"
echo "V6 ='$V6'"
echo "V7 ='$V7'"
echo "V8 ='$V8'"
echo "V9 ='$V9'"
else
if [ $Q = "N" ] ; then echo "Simple test success" ; fi
fi
#####################################################
# Known text checks (data made with perl script)
#####################################################
function known {
kC=$4
kM=$3
kB=$2
Base64_Conv_Func B -i raw -q -e -o cryptBS $1
Base64_Conv_Func C -i raw -q -e -o crypt $1
Base64_Conv_Func M -i raw -q -e -o mime $1
T=yes
if [ x$B != x$kB ];
then
echo "Known test failed (cryptBS). '$1' should be '$kB' not '$B'"
T=no
((FAILS++))
fi
if [ x$M != x$kM ];
then
echo "Known test failed (mime). '$1' should be '$kM' not '$M'"
T=no
((FAILS++))
fi
if [ x$C != x$kC ];
then
echo "Known test failed (crypt). '$1' should be '$kC' not '$C'"
T=no
((FAILS++))
fi
Base64_Conv_Func C2 -i cryptBS -q -e -o crypt $B
Base64_Conv_Func M2 -i cryptBS -q -e -o mime $B
if [ x$M2 != x$kM ];
then
echo "Known test failed (cryptBS->mime). '$1' should be '$kM' not '$M2'"
T=no
((FAILS++))
fi
if [ x$C2 != x$kC ];
then
echo "Known test failed (cryptBS->crypt). '$1' should be '$kC' not '$C2'"
T=no
((FAILS++))
fi
Base64_Conv_Func B2 -i crypt -q -e -o cryptBS $C
Base64_Conv_Func M2 -i crypt -q -e -o mime $C
if [ x$M2 != x$kM ];
then
echo "Known test failed (crypt->mime). '$1' should be '$kM' not '$M2'"
T=no
((FAILS++))
fi
if [ x$B2 != x$kB ];
then
echo "Known test failed (crypt->cryptBS). '$1' should be '$kB' not '$B2'"
T=no
((FAILS++))
fi
Base64_Conv_Func B2 -i mime -q -e -o cryptBS $M
Base64_Conv_Func C2 -i mime -q -e -o crypt $M
if [ x$C2 != x$kC ];
then
echo "Known test failed (mime->crypt). '$1' should be '$kC' not '$C2'"
T=no
((FAILS++))
fi
if [ x$B2 != x$kB ];
then
echo "Known test failed (mime->cryptBS). '$1' should be '$kB' not '$B2'"
T=no
((FAILS++))
fi
if [ x$T = "xyes" ];
then
if [ $Q = "N" ] ; then echo "Success known test param = $1" ; fi
else
echo "Failure known test param = $1"
fi
}
known abcdefghijklmnopqrstuvwxyz12345 V7qMYJaNbVKOeh4PhtqPk3bQnFLRqR5StdLAmA1Bp. YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoxMjM0NQ MK7XN4JaNqVdOahgPKtjQ53mQrFpRbRsSLclAXAoBE
known abcdefghijklmnopqrstuvwxyz123456 V7qMYJaNbVKOeh4PhtqPk3bQnFLRqR5StdLAmA1BpM1 YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoxMjM0NTY MK7XN4JaNqVdOahgPKtjQ53mQrFpRbRsSLclAXAoBHM
known abcdefghijklmnopqrstuvwxyz1234567 V7qMYJaNbVKOeh4PhtqPk3bQnFLRqR5StdLAmA1BpMnB YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoxMjM0NTY3 MK7XN4JaNqVdOahgPKtjQ53mQrFpRbRsSLclAXAoBHMr
known abcdefghijklmnopqrstuvwxyz12345678 V7qMYJaNbVKOeh4PhtqPk3bQnFLRqR5StdLAmA1BpMnBs. YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoxMjM0NTY3OA MK7XN4JaNqVdOahgPKtjQ53mQrFpRbRsSLclAXAoBHMrC.
known abcdefghijklmnopqrstuvwxyz123456789 V7qMYJaNbVKOeh4PhtqPk3bQnFLRqR5StdLAmA1BpMnBsY1 YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoxMjM0NTY3ODk MK7XN4JaNqVdOahgPKtjQ53mQrFpRbRsSLclAXAoBHMrC1Y
known abcdefghijklmnopqrstuvwxyz1234567890 V7qMYJaNbVKOeh4PhtqPk3bQnFLRqR5StdLAmA1BpMnBsY1A YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoxMjM0NTY3ODkw MK7XN4JaNqVdOahgPKtjQ53mQrFpRbRsSLclAXAoBHMrC1Yk
known abcdefghijklmnopqrstuvwxyz12345678901 V7qMYJaNbVKOeh4PhtqPk3bQnFLRqR5StdLAmA1BpMnBsY1Al. YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoxMjM0NTY3ODkwMQ MK7XN4JaNqVdOahgPKtjQ53mQrFpRbRsSLclAXAoBHMrC1YkAE
known abcdefghijklmnopqrstuvwxyz123456789012 V7qMYJaNbVKOeh4PhtqPk3bQnFLRqR5StdLAmA1BpMnBsY1Al61 YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoxMjM0NTY3ODkwMTI MK7XN4JaNqVdOahgPKtjQ53mQrFpRbRsSLclAXAoBHMrC1YkAH6
known abcdefghijklmnopqrstuvwxyz1234567890123 V7qMYJaNbVKOeh4PhtqPk3bQnFLRqR5StdLAmA1BpMnBsY1Al6nA YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoxMjM0NTY3ODkwMTIz MK7XN4JaNqVdOahgPKtjQ53mQrFpRbRsSLclAXAoBHMrC1YkAH6n
known abcdefghijklmnopqrstuvwxyz12345678901234 V7qMYJaNbVKOeh4PhtqPk3bQnFLRqR5StdLAmA1BpMnBsY1Al6nAo. YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoxMjM0NTY3ODkwMTIzNA MK7XN4JaNqVdOahgPKtjQ53mQrFpRbRsSLclAXAoBHMrC1YkAH6nB.
known abcdefghijklmnopqrstuvwxyz123456789012345 V7qMYJaNbVKOeh4PhtqPk3bQnFLRqR5StdLAmA1BpMnBsY1Al6nAoI1 YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoxMjM0NTY3ODkwMTIzNDU MK7XN4JaNqVdOahgPKtjQ53mQrFpRbRsSLclAXAoBHMrC1YkAH6nB1I
known abcdefghijklmnopqrstuvwxyz1234567890123456 V7qMYJaNbVKOeh4PhtqPk3bQnFLRqR5StdLAmA1BpMnBsY1Al6nAoIXB YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoxMjM0NTY3ODkwMTIzNDU2 MK7XN4JaNqVdOahgPKtjQ53mQrFpRbRsSLclAXAoBHMrC1YkAH6nB1Iq
# null check. Make sure we can properly handle NULL buffers.
if [ $Q = "N" ] ; then echo "performing NULL checks" ; fi
T=yes
B2=000000000000
C2=........
Base64_Conv_Func B -q -i hex -o crypt $B2
Base64_Conv_Func C -q -o hex -i crypt $C2
if [ x$B != "x$C2" -o x$C != "x$B2" ];
then
echo "failed! crypt";
T=no
((FAILS++))
fi
Base64_Conv_Func B -q -i hex -o cryptBS $B2
Base64_Conv_Func C -q -o hex -i cryptBS $C2
if [ x$B != "x$C2" -o x$C != "x$B2" ];
then
echo "failed! cryptBS";
T=no
((FAILS++))
fi
C2=AAAAAAAA
Base64_Conv_Func B -q -i hex -o mime $B2
Base64_Conv_Func C -q -o hex -i mime $C2
if [ x$B != "x$C2" -o x$C != "x$B2" ];
then
echo "failed! mime";
T=no
((FAILS++))
fi
if [ x$T = "xyes" ]; then
if [ $Q = "N" ] ; then echo "ALL null tests were valid" ; fi
fi
#########################################
# Conversion from all formats
# to others tests, for many
# lengths.
#########################################
function comp {
if [ x$1 != x$2 ];
then
echo "$3: '$1' is not equal to '$2'"
T=no
((FAILS++))
fi
}
function tst {
T=yes
Base64_Conv_Func B -i raw -q -e -o cryptBS $1
Base64_Conv_Func C -i raw -q -e -o crypt $1
Base64_Conv_Func M -i raw -q -e -o mime $1
Base64_Conv_Func R -i crypt -q -e -o cryptBS $C
Base64_Conv_Func R -i cryptBS -q -e -o raw $R
comp x$1 x$R "crypt_cryptBS (1)"
Base64_Conv_Func R -i mime -q -e -o cryptBS $M
Base64_Conv_Func R -i cryptBS -q -e -o raw $R
comp x$1 x$R "mime_cryptBS (2)"
Base64_Conv_Func R -i cryptBS -q -e -o crypt $B
Base64_Conv_Func R -i crypt -q -e -o raw $R
comp x$1 x$R "cryptBS_crypt (3)"
Base64_Conv_Func R -i mime -q -e -o crypt $M
Base64_Conv_Func R -i crypt -q -e -o raw $R
comp x$1 x$R "mime_crypt (4)"
Base64_Conv_Func R -i cryptBS -q -e -o mime $B
Base64_Conv_Func R -i mime -q -e -o raw $R
comp a$1 a$R "cryptBS_mime (5)"
Base64_Conv_Func R -i crypt -q -e -o mime $C
Base64_Conv_Func R -i mime -q -e -o raw $R
comp b$1 b$R "crypt_mime (6)"
if [ x$T = "xyes" ];
then
if [ $Q = "N" ] ; then echo "Success multi-convert test param = $1" ; fi
else
echo "Failure multi-convert test param = $1"
fi
}
P=fadsgragabsrgahseeEDTa
tst $P
P=fadsgragabsrgahseeEDTa0
tst $P
P=fadsgragabsrgahseeEDTa0~
tst $P
P=fadsgragabsrgahseeEDTa0~~
tst $P
P=fadsgragabsrgahseeEDTa06x~
tst $P
P=xyhadhWaeFgAcwbsex03dz
tst $P
P=xyhadhWaeFgAcwbsex03dzZ
tst $P
P=xyhadhWaeFgAcwbsex03dzZ~
tst $P
P=xyhadhWaeFgAcwbsex03dzZ~~
tst $P
P=xyhadhWaeFgAcwbsex03dzZ~Z!
tst $P
############################# Total random data (79 character working set)
P=PoQC,jTymI=GAPzLqs#B1@T-
tst $P
P=kbHAP_E3YWQk0/DhFj,zwO_,y
tst $P
P=p#OzRPQmEbgA!s:@dZ9nY@0dM,
tst $P
P=VGS%nUC0!@.#n3vOEDylfwA-}Rm
tst $P
P=zn}O=GYzi=LmXREZ,yYGuMNCcmZd
tst $P
P=QC*9P*myY5bAmebFK!TU4GQcZBUTA
tst $P
P=}mbfdKKG4cAxiDFfOLmO0kV{6Hg:nB
tst $P
P=~AaQZgLQ2Gxw11V_^KMVsi1pz0eR=m{
tst $P
P=V#@*jGWk=hq_p~h7B%JpDa%y
tst $P
P=uKHo,ipa7zpAeP4^/3oslwrrQ
tst $P
P=g%Fz_MN,0z~{/WJdp5BYhfH_L5
tst $P
P=,60L4e?Q=sNgBjRMI7Msec~mmf=
tst $P
P=8yQDJ4TpZJS0EgUCisBHtLO?k:LU
tst $P
P=rn-p5!JD4FyS-e41C=B:G__SMt!7z
tst $P
P=LvCRbk9bv1EuOn0PeX7AioktY2Lo2f
tst $P
P=.UusOL3m-m?rJC,a73od--KHUFpFLV5
tst $P
P=U3CrvW7Sey!YVF8_}c5dv8,3
tst $P
P=vc#uqCCyQHG_H@iXYI!1Ekbew
tst $P
P=/AVO!,lcQDX=u}PaOU7iaWAyW}
tst $P
P=H7BX8}iLz95AETxC@MDO@l@lS^6
tst $P
P=F15off04-HvYwrpat#9}vhd6umLv
tst $P
P=vWwUr6WBw0eRq@hW~RAUwyu%AR/l2
tst $P
P=8{NI-Kf9Kz0A=Xsx1SDYc?yMG2@fyr
tst $P
P=a^Tbt51QvhiTK2#2S-!z7cP*dRNPB6A
tst $P
P=C.?OkU=62rb8ZW6DS8D5S6!G
tst $P
P=xe0_mbgdqClK1MDK4zdSo-zyH
tst $P
P=3=4xxAcCUJd:m0/DsO%bTeE^An
tst $P
P=7qu*9pIvL~x@BmKxry?kwNn%*?W
tst $P
P=ANnvk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WwBMNWCG8sKy7:e{%0gph
tst $P
P=Yqvylp6J8VJiDIjD3}e}YIkhgj
tst $P
P=Je-.F7,uCyE.dOQ?EFXZlsGJ^An
tst $P
P=:80=Axv}Te,D%Jbm?kBYj0N!*^G:
tst $P
P=pk-AsxOFR6PjIf?5~@tTK2O*F0*jl
tst $P
P=YxafCV0Y6~hf*NejEIO}d_Y@YeO%#m
tst $P
P=?1FM^6Al=2j:A:rqXtj3Y/}F?4dc1op
tst $P
P=tCt6Zp1AU7lg3Odr/,FyK%6N
tst $P
P=qXcXV5l,WxyzL07gAD3ErWt8M
tst $P
P=N^US17db.UPyCFytM@Zi61Jw7H
tst $P
P=T7V=j_isiXTLhlcEFUvMD*a3Y38
tst $P
P=vYSTO~MTgv_858XO@@4wgxVZyxiZ
tst $P
P=n*Qf{DaPAn%9pPAn-O0}8D{wybx=H
tst $P
P=.4UB2waQQid#y20WEj{Pq-MC1-~Mf^
tst $P
P=9*,bFT@ZR%,NC9/L8L_0sDx#8dNzCPK
tst $P
P=:77Ewp}pAbvvgR@%PeP1QYd^
tst $P
P=_zvLTkP0_{ZscGIou:KM8LAM8
tst $P
P=h:UbNTGHm%D6ir~zvqL4us_X1d
tst $P
P=.UXe%~K3Qtizdj80*nc#Hj%C=to
tst $P
P=I!CRw1V:mN0L@^D0O?aMN%DBk?f-
tst $P
P=BmxKQkHMIt2j:C=?hUP.ZIRiyA7f{
tst $P
P={Sa,u/{d=.rWKc3{8ygV!cyIVA*=3H
tst $P
P=c5LZJcSu8HhpH%7=BdEIo}2#iMS4fwS
tst $P
# if there were no failures, then list so. This is so there
# is SOME output in -q mode, if all tests passed.
if [ x$FAILS = "x0" ] ; then
echo "All tests succeeded. $TOTAL calls to ../run/base64conv"
else
echo "There were $FAILS failures, from $TOTAL calls to ../run/base64conv"
fi