Apache HTTPD
testencode.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <assert.h>
18#include <stdio.h>
19#include <stdlib.h>
20
21#include "apr_encode.h"
22#include "apr_strings.h"
23
24#include "abts.h"
25#include "testutil.h"
26
27static const unsigned char ufoobar[] = { 'f', 'o', 'o', 'b', 'a', 'r' };
28
29static void test_encode_base64(abts_case * tc, void *data)
30{
32 const char *src, *target;
33 const char *dest;
35
37
38 /*
39 * Test vectors from https://tools.ietf.org/html/rfc4648#section-10
40 */
41 src = "";
42 target = "";
44 ABTS_STR_EQUAL(tc, target, dest);
45
46 src = "f";
47 target = "Zg==";
49 ABTS_STR_EQUAL(tc, target, dest);
50
51 src = "f";
52 target = "Zg";
54 ABTS_STR_EQUAL(tc, target, dest);
55
56 src = "fo";
57 target = "Zm8=";
59 ABTS_STR_EQUAL(tc, target, dest);
60
61 src = "fo";
62 target = "Zm8";
64 ABTS_STR_EQUAL(tc, target, dest);
65
66 src = "foo";
67 target = "Zm9v";
69 ABTS_STR_EQUAL(tc, target, dest);
70
71 src = "foo";
72 target = "Zm9v";
74 ABTS_STR_EQUAL(tc, target, dest);
75
77}
78
80{
82 const char *target;
83 const char *dest;
85
87
88 /*
89 * Test vectors from https://tools.ietf.org/html/rfc4648#section-10
90 */
91 target = "";
93 ABTS_STR_EQUAL(tc, target, dest);
94
95 target = "Zg==";
97 ABTS_STR_EQUAL(tc, target, dest);
98
99 target = "Zg";
101 ABTS_STR_EQUAL(tc, target, dest);
102
103 target = "Zm8=";
105 ABTS_STR_EQUAL(tc, target, dest);
106
107 target = "Zm8";
109 ABTS_STR_EQUAL(tc, target, dest);
110
111 target = "Zm9v";
113 ABTS_STR_EQUAL(tc, target, dest);
114
115 target = "Zm9v";
117 ABTS_STR_EQUAL(tc, target, dest);
118
120}
121
122static void test_decode_base64(abts_case * tc, void *data)
123{
125 const char *target, *src;
126 const char *dest;
128
130
131 /*
132 * Test vectors from https://tools.ietf.org/html/rfc4648#section-10
133 */
134 src = "";
135 target = "";
137 ABTS_STR_EQUAL(tc, target, dest);
138
139 src = "Zg==";
140 target = "f";
142 ABTS_STR_EQUAL(tc, target, dest);
143
144 src = "Zg=";
145 target = "f";
147 ABTS_STR_EQUAL(tc, target, dest);
148
149 src = "Zg";
150 target = "f";
152 ABTS_STR_EQUAL(tc, target, dest);
153
154 src = "Zm8=";
155 target = "fo";
157 ABTS_STR_EQUAL(tc, target, dest);
158
159 src = "Zm8";
160 target = "fo";
162 ABTS_STR_EQUAL(tc, target, dest);
163
164 src = "Zm9v";
165 target = "foo";
167 ABTS_STR_EQUAL(tc, target, dest);
168
169 src = "Zm9v";
170 target = "foo";
172 ABTS_STR_EQUAL(tc, target, dest);
173
175}
176
178{
180 const char *src;
181 const unsigned char *udest;
183
185
186 /*
187 * Test vectors from https://tools.ietf.org/html/rfc4648#section-10
188 */
189 src = "";
191 ABTS_ASSERT(tc, "apr_pdecode_base64_binary target!=dest", memcmp(ufoobar, udest, 0) == 0);
192 ABTS_SIZE_EQUAL(tc, len, 0);
193
194 src = "Zg==";
196 ABTS_ASSERT(tc, "apr_pdecode_base64_binary target!=dest", memcmp(ufoobar, udest, 1) == 0);
197 ABTS_SIZE_EQUAL(tc, len, 1);
198
199 src = "Zg=";
201 ABTS_ASSERT(tc, "apr_pdecode_base64_binary target!=dest", memcmp(ufoobar, udest, 1) == 0);
202 ABTS_SIZE_EQUAL(tc, len, 1);
203
204 src = "Zg";
206 ABTS_ASSERT(tc, "apr_pdecode_base64_binary target!=dest", memcmp(ufoobar, udest, 1) == 0);
207 ABTS_SIZE_EQUAL(tc, len, 1);
208
209 src = "Zm8=";
211 ABTS_ASSERT(tc, "apr_pdecode_base64_binary target!=dest", memcmp(ufoobar, udest, 2) == 0);
212 ABTS_SIZE_EQUAL(tc, len, 2);
213
214 src = "Zm8";
216 ABTS_ASSERT(tc, "apr_pdecode_base64_binary target!=dest", memcmp(ufoobar, udest, 2) == 0);
217 ABTS_SIZE_EQUAL(tc, len, 2);
218
219 src = "Zm9v";
221 ABTS_ASSERT(tc, "apr_pdecode_base64_binary target!=dest", memcmp(ufoobar, udest, 3) == 0);
222 ABTS_SIZE_EQUAL(tc, len, 3);
223
224 src = "Zm9v";
226 ABTS_ASSERT(tc, "apr_pdecode_base64_binary target!=dest", memcmp(ufoobar, udest, 3) == 0);
227 ABTS_SIZE_EQUAL(tc, len, 3);
228
230}
231
232static void test_encode_base32(abts_case * tc, void *data)
233{
235 const char *src, *target;
236 const char *dest;
238
240
241 /*
242 * Test vectors from https://tools.ietf.org/html/rfc4648#section-10
243 */
244 src = "";
245 target = "";
247 ABTS_STR_EQUAL(tc, target, dest);
248
249 src = "f";
250 target = "MY======";
252 ABTS_STR_EQUAL(tc, target, dest);
253
254 src = "f";
255 target = "MY";
257 ABTS_STR_EQUAL(tc, target, dest);
258
259 src = "f";
260 target = "CO======";
262 ABTS_STR_EQUAL(tc, target, dest);
263
264 src = "f";
265 target = "CO";
267 ABTS_STR_EQUAL(tc, target, dest);
268
269 src = "fo";
270 target = "MZXQ====";
272 ABTS_STR_EQUAL(tc, target, dest);
273
274 src = "fo";
275 target = "MZXQ";
277 ABTS_STR_EQUAL(tc, target, dest);
278
279 src = "fo";
280 target = "CPNG====";
282 ABTS_STR_EQUAL(tc, target, dest);
283
284 src = "fo";
285 target = "CPNG";
287 ABTS_STR_EQUAL(tc, target, dest);
288
289 src = "foo";
290 target = "MZXW6===";
292 ABTS_STR_EQUAL(tc, target, dest);
293
294 src = "foo";
295 target = "MZXW6";
297 ABTS_STR_EQUAL(tc, target, dest);
298
299 src = "foo";
300 target = "CPNMU===";
302 ABTS_STR_EQUAL(tc, target, dest);
303
304 src = "foo";
305 target = "CPNMU";
307 ABTS_STR_EQUAL(tc, target, dest);
308
309 src = "foob";
310 target = "MZXW6YQ=";
312 ABTS_STR_EQUAL(tc, target, dest);
313
314 src = "foob";
315 target = "MZXW6YQ";
317 ABTS_STR_EQUAL(tc, target, dest);
318
319 src = "foob";
320 target = "CPNMUOG=";
322 ABTS_STR_EQUAL(tc, target, dest);
323
324 src = "foob";
325 target = "CPNMUOG";
327 ABTS_STR_EQUAL(tc, target, dest);
328
329 src = "fooba";
330 target = "MZXW6YTB";
332 ABTS_STR_EQUAL(tc, target, dest);
333
334 src = "fooba";
335 target = "MZXW6YTB";
337 ABTS_STR_EQUAL(tc, target, dest);
338
339 src = "fooba";
340 target = "CPNMUOJ1";
342 ABTS_STR_EQUAL(tc, target, dest);
343
344 src = "fooba";
345 target = "CPNMUOJ1";
347 ABTS_STR_EQUAL(tc, target, dest);
348
349 src = "foobar";
350 target = "MZXW6YTBOI======";
352 ABTS_STR_EQUAL(tc, target, dest);
353
354 src = "foobar";
355 target = "MZXW6YTBOI";
357 ABTS_STR_EQUAL(tc, target, dest);
358
359 src = "foobar";
360 target = "CPNMUOJ1E8======";
362 ABTS_STR_EQUAL(tc, target, dest);
363
364 src = "foobar";
365 target = "CPNMUOJ1E8";
367 ABTS_STR_EQUAL(tc, target, dest);
368
370}
371
373{
375 const char *target;
376 const char *dest;
378
380
381 /*
382 * Test vectors from https://tools.ietf.org/html/rfc4648#section-10
383 */
384 target = "";
386 ABTS_STR_EQUAL(tc, target, dest);
387
388 target = "MY======";
390 ABTS_STR_EQUAL(tc, target, dest);
391
392 target = "MY";
394 ABTS_STR_EQUAL(tc, target, dest);
395
396 target = "CO======";
398 ABTS_STR_EQUAL(tc, target, dest);
399
400 target = "CO";
402 ABTS_STR_EQUAL(tc, target, dest);
403
404 target = "MZXQ====";
406 ABTS_STR_EQUAL(tc, target, dest);
407
408 target = "MZXQ";
410 ABTS_STR_EQUAL(tc, target, dest);
411
412 target = "CPNG====";
414 ABTS_STR_EQUAL(tc, target, dest);
415
416 target = "CPNG";
418 ABTS_STR_EQUAL(tc, target, dest);
419
420 target = "MZXW6===";
422 ABTS_STR_EQUAL(tc, target, dest);
423
424 target = "MZXW6";
426 ABTS_STR_EQUAL(tc, target, dest);
427
428 target = "CPNMU===";
430 ABTS_STR_EQUAL(tc, target, dest);
431
432 target = "CPNMU";
434 ABTS_STR_EQUAL(tc, target, dest);
435
436 target = "MZXW6YQ=";
438 ABTS_STR_EQUAL(tc, target, dest);
439
440 target = "MZXW6YQ";
442 ABTS_STR_EQUAL(tc, target, dest);
443
444 target = "CPNMUOG=";
446 ABTS_STR_EQUAL(tc, target, dest);
447
448 target = "CPNMUOG";
450 ABTS_STR_EQUAL(tc, target, dest);
451
452 target = "MZXW6YTB";
454 ABTS_STR_EQUAL(tc, target, dest);
455
456 target = "MZXW6YTB";
458 ABTS_STR_EQUAL(tc, target, dest);
459
460 target = "CPNMUOJ1";
462 ABTS_STR_EQUAL(tc, target, dest);
463
464 target = "CPNMUOJ1";
466 ABTS_STR_EQUAL(tc, target, dest);
467
468 target = "MZXW6YTBOI======";
470 ABTS_STR_EQUAL(tc, target, dest);
471
472 target = "MZXW6YTBOI";
474 ABTS_STR_EQUAL(tc, target, dest);
475
476 target = "CPNMUOJ1E8======";
478 ABTS_STR_EQUAL(tc, target, dest);
479
480 target = "CPNMUOJ1E8";
482 ABTS_STR_EQUAL(tc, target, dest);
483
485}
486
487static void test_decode_base32(abts_case * tc, void *data)
488{
490 const char *target, *src;
491 const char *dest;
493
495
496 /*
497 * Test vectors from https://tools.ietf.org/html/rfc4648#section-10
498 */
499 src = "";
500 target = "";
502 ABTS_STR_EQUAL(tc, target, dest);
503
504 src = "MY======";
505 target = "f";
507 ABTS_STR_EQUAL(tc, target, dest);
508
509 src = "MY";
510 target = "f";
512 ABTS_STR_EQUAL(tc, target, dest);
513
514 src = "CO======";
515 target = "f";
517 ABTS_STR_EQUAL(tc, target, dest);
518
519 src = "CO";
520 target = "f";
522 ABTS_STR_EQUAL(tc, target, dest);
523
524 src = "MZXQ====";
525 target = "fo";
527 ABTS_STR_EQUAL(tc, target, dest);
528
529 src = "MZXQ";
530 target = "fo";
532 ABTS_STR_EQUAL(tc, target, dest);
533
534 src = "CPNG====";
535 target = "fo";
537 ABTS_STR_EQUAL(tc, target, dest);
538
539 src = "CPNG";
540 target = "fo";
542 ABTS_STR_EQUAL(tc, target, dest);
543
544 src = "MZXW6===";
545 target = "foo";
547 ABTS_STR_EQUAL(tc, target, dest);
548
549 src = "MZXW6";
550 target = "foo";
552 ABTS_STR_EQUAL(tc, target, dest);
553
554 src = "CPNMU===";
555 target = "foo";
557 ABTS_STR_EQUAL(tc, target, dest);
558
559 src = "CPNMU";
560 target = "foo";
562 ABTS_STR_EQUAL(tc, target, dest);
563
564 src = "MZXW6YQ=";
565 target = "foob";
567 ABTS_STR_EQUAL(tc, target, dest);
568
569 src = "MZXW6YQ=";
570 target = "foob";
572 ABTS_STR_EQUAL(tc, target, dest);
573
574 src = "CPNMUOG=";
575 target = "foob";
577 ABTS_STR_EQUAL(tc, target, dest);
578
579 src = "CPNMUOG";
580 target = "foob";
582 ABTS_STR_EQUAL(tc, target, dest);
583
584 src = "MZXW6YTB";
585 target = "fooba";
587 ABTS_STR_EQUAL(tc, target, dest);
588
589 src = "MZXW6YTB";
590 target = "fooba";
592 ABTS_STR_EQUAL(tc, target, dest);
593
594 src = "CPNMUOJ1";
595 target = "fooba";
597 ABTS_STR_EQUAL(tc, target, dest);
598
599 src = "CPNMUOJ1";
600 target = "fooba";
602 ABTS_STR_EQUAL(tc, target, dest);
603
604 src = "MZXW6YTBOI======";
605 target = "foobar";
607 ABTS_STR_EQUAL(tc, target, dest);
608
609 src = "MZXW6YTBOI";
610 target = "foobar";
612 ABTS_STR_EQUAL(tc, target, dest);
613
614 src = "CPNMUOJ1E8======";
615 target = "foobar";
617 ABTS_STR_EQUAL(tc, target, dest);
618
619 src = "CPNMUOJ1E8";
620 target = "foobar";
622 ABTS_STR_EQUAL(tc, target, dest);
623
625}
626
628{
630 const char *src;
631 const unsigned char *udest;
633
635
636 /*
637 * Test vectors from https://tools.ietf.org/html/rfc4648#section-10
638 */
639 src = "";
641 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 0) == 0);
642 ABTS_SIZE_EQUAL(tc, 0, len);
643
644 src = "MY======";
646 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 1) == 0);
647 ABTS_SIZE_EQUAL(tc, 1, len);
648
649 src = "MY";
651 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 1) == 0);
652 ABTS_SIZE_EQUAL(tc, 1, len);
653
654 src = "CO======";
656 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 1) == 0);
657 ABTS_SIZE_EQUAL(tc, 1, len);
658
659 src = "CO";
661 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 1) == 0);
662 ABTS_SIZE_EQUAL(tc, 1, len);
663
664 src = "MZXQ====";
666 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 2) == 0);
667 ABTS_SIZE_EQUAL(tc, 2, len);
668
669 src = "MZXQ";
671 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 2) == 0);
672 ABTS_SIZE_EQUAL(tc, 2, len);
673
674 src = "CPNG====";
676 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 2) == 0);
677 ABTS_SIZE_EQUAL(tc, 2, len);
678
679 src = "CPNG";
681 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 2) == 0);
682 ABTS_SIZE_EQUAL(tc, 2, len);
683
684 src = "MZXW6===";
686 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 3) == 0);
687 ABTS_SIZE_EQUAL(tc, 3, len);
688
689 src = "MZXW6";
691 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 3) == 0);
692 ABTS_SIZE_EQUAL(tc, 3, len);
693
694 src = "CPNMU===";
696 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 3) == 0);
697 ABTS_SIZE_EQUAL(tc, 3, len);
698
699 src = "CPNMU";
701 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 3) == 0);
702 ABTS_SIZE_EQUAL(tc, 3, len);
703
704 src = "MZXW6YQ=";
706 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 4) == 0);
707 ABTS_SIZE_EQUAL(tc, 4, len);
708
709 src = "MZXW6YQ=";
711 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 4) == 0);
712 ABTS_SIZE_EQUAL(tc, 4, len);
713
714 src = "CPNMUOG=";
716 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 4) == 0);
717 ABTS_SIZE_EQUAL(tc, 4, len);
718
719 src = "CPNMUOG";
721 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 4) == 0);
722 ABTS_SIZE_EQUAL(tc, 4, len);
723
724 src = "MZXW6YTB";
726 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 5) == 0);
727 ABTS_SIZE_EQUAL(tc, 5, len);
728
729 src = "MZXW6YTB";
731 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 5) == 0);
732 ABTS_SIZE_EQUAL(tc, 5, len);
733
734 src = "CPNMUOJ1";
736 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 5) == 0);
737 ABTS_SIZE_EQUAL(tc, 5, len);
738
739 src = "CPNMUOJ1";
741 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 5) == 0);
742 ABTS_SIZE_EQUAL(tc, 5, len);
743
744 src = "MZXW6YTBOI======";
746 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 6) == 0);
747 ABTS_SIZE_EQUAL(tc, 6, len);
748
749 src = "MZXW6YTBOI";
751 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 6) == 0);
752 ABTS_SIZE_EQUAL(tc, 6, len);
753
754 src = "CPNMUOJ1E8======";
756 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 6) == 0);
757 ABTS_SIZE_EQUAL(tc, 6, len);
758
759 src = "CPNMUOJ1E8";
761 ABTS_ASSERT(tc, "apr_pdecode_base32_binary target!=dest", memcmp(ufoobar, udest, 6) == 0);
762 ABTS_SIZE_EQUAL(tc, 6, len);
763
765}
766
767static void test_encode_base16(abts_case * tc, void *data)
768{
770 const char *src, *target;
771 const char *dest;
773
775
776 src = "foobar";
777 target = "666f6f626172";
779 ABTS_STR_EQUAL(tc, target, dest);
781 ABTS_ASSERT(tc,
782 apr_psprintf(pool, "size mismatch (%" APR_SIZE_T_FMT "!=%" APR_SIZE_T_FMT ")", len, strlen(dest) + 1),
783 (len == strlen(dest) + 1));
784
785 src = "foobar";
786 target = "666F6F626172";
788 ABTS_STR_EQUAL(tc, target, dest);
790 ABTS_ASSERT(tc,
791 apr_psprintf(pool, "size mismatch (%" APR_SIZE_T_FMT "!=%" APR_SIZE_T_FMT ")", len, strlen(dest) + 1),
792 (len == strlen(dest) + 1));
793
794 src = "foobar";
795 target = "66:6f:6f:62:61:72";
797 ABTS_STR_EQUAL(tc, target, dest);
799 ABTS_ASSERT(tc,
800 apr_psprintf(pool, "size mismatch (%" APR_SIZE_T_FMT "!=%" APR_SIZE_T_FMT ")", len, strlen(dest) + 1),
801 (len == strlen(dest) + 1));
802
803 src = "foobar";
804 target = "66:6F:6F:62:61:72";
806 ABTS_STR_EQUAL(tc, target, dest);
808 ABTS_ASSERT(tc,
809 apr_psprintf(pool, "size mismatch (%" APR_SIZE_T_FMT "!=%" APR_SIZE_T_FMT ")", len, strlen(dest) + 1),
810 (len == strlen(dest) + 1));
811
813}
814
816{
818 const char *target;
819 const unsigned char usrc[] = {
820 0xFF, 0x00, 0xFF, 0x00
821 };
822 const char *dest;
824
826
827 target = "ff00ff00";
829 ABTS_STR_EQUAL(tc, target, dest);
831 ABTS_ASSERT(tc,
832 apr_psprintf(pool, "size mismatch (%" APR_SIZE_T_FMT "!=%" APR_SIZE_T_FMT ")", len, strlen(dest) + 1),
833 (len == strlen(dest) + 1));
834
835 target = "FF00FF00";
837 ABTS_STR_EQUAL(tc, target, dest);
839 ABTS_ASSERT(tc,
840 apr_psprintf(pool, "size mismatch (%" APR_SIZE_T_FMT "!=%" APR_SIZE_T_FMT ")", len, strlen(dest) + 1),
841 (len == strlen(dest) + 1));
842
843 target = "ff:00:ff:00";
845 ABTS_STR_EQUAL(tc, target, dest);
847 ABTS_ASSERT(tc,
848 apr_psprintf(pool, "size mismatch (%" APR_SIZE_T_FMT "!=%" APR_SIZE_T_FMT ")", len, strlen(dest) + 1),
849 (len == strlen(dest) + 1));
850
851 target = "FF:00:FF:00";
853 ABTS_STR_EQUAL(tc, target, dest);
855 ABTS_ASSERT(tc,
856 apr_psprintf(pool, "size mismatch (%" APR_SIZE_T_FMT "!=%" APR_SIZE_T_FMT ")", len, strlen(dest) + 1),
857 (len == strlen(dest) + 1));
858
860}
861
862static void test_decode_base16(abts_case * tc, void *data)
863{
865 const char *src, *target;
866 const char *dest;
868
870
871 src = "3A:3B:3C:3D";
872 target = ":;<=";
874 ABTS_STR_EQUAL(tc, target, dest);
875 ABTS_SIZE_EQUAL(tc, 4, len);
877 ABTS_ASSERT(tc,
878 apr_psprintf(pool, "size mismatch (%" APR_SIZE_T_FMT "!=%" APR_SIZE_T_FMT ")", len, (apr_size_t) 5),
879 (len == 5));
880
882}
883
885{
887 const char *src;
888 const unsigned char utarget[] = {
889 0xFF, 0x00, 0xFF, 0x00
890 };
891 const unsigned char *udest;
893
895
896 src = "ff:00:ff:00";
898 ABTS_ASSERT(tc, "apr_pdecode_base16_binary target!=dest", memcmp(utarget, udest, 4) == 0);
899 ABTS_SIZE_EQUAL(tc, vlen, 4);
901 ABTS_ASSERT(tc,
902 apr_psprintf(pool, "size mismatch (%" APR_SIZE_T_FMT "!=%" APR_SIZE_T_FMT ")", len, (apr_size_t) 4),
903 (len == 4));
904
906}
907
908static void test_encode_errors(abts_case * tc, void *data)
909{
910 char dest[64];
912 apr_status_t rv;
913
914 /* Can't test APR_ENOSPC without a NUL terminated buffer of
915 * length APR_SIZE_MAX / 4 * 3 and passing APR_ENCODE_STRING,
916 * which we won't even think about :)
917 */
918
919 /* base64 */
920 rv = apr_encode_base64(dest, "", -2, 0, &len);
921 ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
924
925 /* base64_binary */
926 rv = apr_encode_base64_binary(dest, (const unsigned char *)"", -2, 0, &len);
927 ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
930
931 /* base32 */
932 rv = apr_encode_base32(dest, "", -2, 0, &len);
933 ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
936
937 /* base32_binary */
938 rv = apr_encode_base32_binary(dest, (const unsigned char *)"", -2, 0, &len);
939 ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
942
943 /* base16 */
944 rv = apr_encode_base16(dest, "", -2, 0, &len);
945 ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
948
949 /* base16_binary */
950 rv = apr_encode_base16_binary(dest, (const unsigned char *)"", -2, 0, &len);
951 ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
954}
955
956static void test_decode_errors(abts_case * tc, void *data)
957{
958 char dest[64];
960 apr_status_t rv;
961 unsigned char *udest = (unsigned char *)dest;
962
963 /* base64 */
964 rv = apr_decode_base64(dest, "", -2, 0, &len);
965 ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
968 rv = apr_decode_base64(NULL, NULL, 5, 0, &len);
970 rv = apr_decode_base64(dest, "ABCDE", APR_ENCODE_STRING, 0, &len);
972 rv = apr_decode_base64(dest, "ABCD*EF", APR_ENCODE_STRING, 0, &len);
973 ABTS_INT_EQUAL(tc, APR_BADCH, rv);
977 ABTS_SIZE_EQUAL(tc, 3, len);
978
979 /* base64_binary */
980 rv = apr_decode_base64_binary(udest, "", -2, 0, &len);
981 ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
984 rv = apr_decode_base64_binary(NULL, NULL, 5, 0, &len);
989 ABTS_INT_EQUAL(tc, APR_BADCH, rv);
993 ABTS_SIZE_EQUAL(tc, 3, len);
994
995 /* base32 */
996 rv = apr_decode_base32(dest, "", -2, 0, &len);
997 ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
1000 rv = apr_decode_base32(NULL, NULL, 9, 0, &len);
1002 rv = apr_decode_base32(NULL, NULL, 11, 0, &len);
1004 rv = apr_decode_base32(NULL, NULL, 14, 0, &len);
1006 rv = apr_decode_base32(dest, "ABCDEFGHI", APR_ENCODE_STRING, 0, &len);
1008 rv = apr_decode_base32(dest, "ABCDEFGHIJK", APR_ENCODE_STRING, 0, &len);
1010 rv = apr_decode_base32(dest, "ABCDEFGHIJKLMN", APR_ENCODE_STRING, 0, &len);
1012 rv = apr_decode_base32(dest, "ABCDEFGH*IJ", APR_ENCODE_STRING, 0, &len);
1013 ABTS_INT_EQUAL(tc, APR_BADCH, rv);
1014 rv = apr_decode_base32(dest, "ABCEEFGH*IJ", APR_ENCODE_STRING,
1016 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1017 ABTS_SIZE_EQUAL(tc, 5, len);
1018
1019 /* base32_binary */
1020 rv = apr_decode_base32_binary(udest, "", -2, 0, &len);
1021 ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
1024 rv = apr_decode_base32_binary(NULL, NULL, 9, 0, &len);
1026 rv = apr_decode_base32_binary(NULL, NULL, 11, 0, &len);
1028 rv = apr_decode_base32_binary(NULL, NULL, 14, 0, &len);
1030 rv = apr_decode_base32_binary(udest, "ABCDEFGHI", APR_ENCODE_STRING, 0, &len);
1032 rv = apr_decode_base32_binary(udest, "ABCDEFGHIJK", APR_ENCODE_STRING, 0, &len);
1034 rv = apr_decode_base32_binary(udest, "ABCDEFGHIJKLMN", APR_ENCODE_STRING, 0, &len);
1036 rv = apr_decode_base32_binary(udest, "ABCDEFGH*IJ", APR_ENCODE_STRING, 0, &len);
1037 ABTS_INT_EQUAL(tc, APR_BADCH, rv);
1040 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1041 ABTS_SIZE_EQUAL(tc, 5, len);
1042
1043 /* base16 */
1044 rv = apr_decode_base16(dest, "", -2, 0, &len);
1045 ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
1048 rv = apr_decode_base16(NULL, NULL, 3, 0, &len);
1050 rv = apr_decode_base16(dest, "ABC", APR_ENCODE_STRING, 0, &len);
1052 rv = apr_decode_base16(dest, "ABCD*EF", APR_ENCODE_STRING, 0, &len);
1053 ABTS_INT_EQUAL(tc, APR_BADCH, rv);
1054 rv = apr_decode_base16(dest, "ABCD*EF", APR_ENCODE_STRING,
1056 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1057 ABTS_SIZE_EQUAL(tc, 2, len);
1058 /* base16 with colon */
1065 rv = apr_decode_base16(dest, "AB:CD*EF", APR_ENCODE_STRING,
1067 ABTS_INT_EQUAL(tc, APR_BADCH, rv);
1068 rv = apr_decode_base16(dest, "AB:CD*EF", APR_ENCODE_STRING,
1070 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1071 ABTS_SIZE_EQUAL(tc, 2, len);
1072
1073 /* base16_binary */
1074 rv = apr_decode_base16_binary(udest, "", -2, 0, &len);
1075 ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
1078 rv = apr_decode_base16_binary(NULL, NULL, 3, 0, &len);
1082 rv = apr_decode_base16_binary(udest, "ABCD*EF", APR_ENCODE_STRING, 0, &len);
1083 ABTS_INT_EQUAL(tc, APR_BADCH, rv);
1086 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1087 ABTS_SIZE_EQUAL(tc, 2, len);
1088 /* base16_binary with colon */
1097 ABTS_INT_EQUAL(tc, APR_BADCH, rv);
1100 ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
1101 ABTS_SIZE_EQUAL(tc, 2, len);
1102}
1103
const char apr_size_t len
Definition ap_regex.h:187
void abts_run_test(abts_suite *ts, test_func f, void *value)
Definition abts.c:175
#define ABTS_SIZE_EQUAL(a, b, c)
Definition abts.h:121
#define ADD_SUITE(suite)
Definition abts.h:67
#define ABTS_STR_EQUAL(a, b, c)
Definition abts.h:123
#define ABTS_ASSERT(a, b, c)
Definition abts.h:130
#define ABTS_INT_EQUAL(a, b, c)
Definition abts.h:109
APR-UTIL Encoding.
APR Strings library.
#define APR_BADCH
Definition apr_errno.h:457
#define APR_NOTFOUND
Definition apr_errno.h:463
#define APR_EINCOMPLETE
Definition apr_errno.h:328
#define APR_EINVAL
Definition apr_errno.h:711
#define APR_ENCODE_BASE32HEX
Definition apr_encode.h:135
#define APR_ENCODE_COLON
Definition apr_encode.h:140
const char * src
Definition apr_encode.h:167
#define APR_ENCODE_RELAXED
Definition apr_encode.h:115
#define APR_ENCODE_LOWER
Definition apr_encode.h:145
#define APR_ENCODE_NONE
Definition apr_encode.h:110
#define APR_ENCODE_NOPADDING
Definition apr_encode.h:120
#define APR_ENCODE_STRING
Definition apr_encode.h:105
apr_size_t size
const char int apr_pool_t * pool
Definition apr_cstr.h:84
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
void * data
#define apr_pool_create(newpool, parent)
Definition apr_pools.h:322
return NULL
Definition mod_so.c:359
abts_suite * testencode(abts_suite *suite)
static void test_encode_base64_binary(abts_case *tc, void *data)
Definition testencode.c:79
static void test_encode_errors(abts_case *tc, void *data)
Definition testencode.c:908
static void test_encode_base16_binary(abts_case *tc, void *data)
Definition testencode.c:815
static void test_decode_base64(abts_case *tc, void *data)
Definition testencode.c:122
static void test_encode_base32(abts_case *tc, void *data)
Definition testencode.c:232
static void test_decode_base32(abts_case *tc, void *data)
Definition testencode.c:487
static void test_decode_errors(abts_case *tc, void *data)
Definition testencode.c:956
static void test_decode_base64_binary(abts_case *tc, void *data)
Definition testencode.c:177
static void test_encode_base64(abts_case *tc, void *data)
Definition testencode.c:29
static void test_decode_base16(abts_case *tc, void *data)
Definition testencode.c:862
static void test_decode_base16_binary(abts_case *tc, void *data)
Definition testencode.c:884
static const unsigned char ufoobar[]
Definition testencode.c:27
static void test_decode_base32_binary(abts_case *tc, void *data)
Definition testencode.c:627
static void test_encode_base32_binary(abts_case *tc, void *data)
Definition testencode.c:372
static void test_encode_base16(abts_case *tc, void *data)
Definition testencode.c:767