4 #include "testParams.h"
9 #include <utilLib/common.h>
10 #include <utilLib/cspwrap.h>
11 #include <Security/SecAsn1Coder.h>
12 #include <Security/SecAsn1Templates.h>
16 #define DO_BAD_DECODE 0
17 #define DO_PAUSE 0 /* for malloc debug */
19 /* good DER, bad DER */
20 static CSSM_DATA goodDer
;
21 static CSSM_DATA badDer
;
28 static const SecAsn1Template twoIntsTemp
[] = {
30 0, NULL
, sizeof(twoInts
) },
31 { SEC_ASN1_INTEGER
, offsetof(twoInts
, int1
) },
32 { SEC_ASN1_INTEGER
, offsetof(twoInts
, int2
) },
36 static uint8 int1
[] = {1,2,3};
37 static uint8 int2
[] = {3,4,5,6,7};
39 #define DECODES_PER_LOOP 1
42 TestParams
*testParams
)
45 * DER encode a sequence of two integers
49 ti
.int1
.Length
= sizeof(int1
);
51 ti
.int2
.Length
= sizeof(int2
);
53 /* encode --> tempDer */
54 SecAsn1CoderRef coder
;
55 SecAsn1CoderCreate(&coder
);
57 CSSM_DATA tmpDer
= {0, NULL
};
58 if(SecAsn1EncodeItem(coder
, &ti
, twoIntsTemp
, &tmpDer
)) {
59 printf("***derDecodeInit: Error on encodeItem()\n");
63 /* copy to goodDer and badDer */
64 appCopyCssmData(&tmpDer
, &goodDer
);
65 appCopyCssmData(&tmpDer
, &badDer
);
67 /* increment the length of the outer sequence to force error */
69 SecAsn1CoderRelease(coder
);
73 int derDecodeTest(TestParams
*testParams
)
75 /* which flavor - good or bad? */
76 const CSSM_DATA
*derSrc
;
77 bool expectErr
= false;
79 if((testParams
->threadNum
& 1) || !DO_BAD_DECODE
) {
86 for(unsigned loop
=0; loop
<testParams
->numLoops
; loop
++) {
87 if(testParams
->verbose
) {
88 printf("derDecode thread %d: loop %d\n",
89 testParams
->threadNum
, loop
);
91 else if(!testParams
->quiet
) {
92 printChar(testParams
->progressChar
);
95 for(unsigned dex
=0; dex
<DECODES_PER_LOOP
; dex
++) {
96 SecAsn1CoderRef coder
;
97 SecAsn1CoderCreate(&coder
);
99 OSStatus perr1
, perr2
;
100 memset(&ti
, 0, sizeof(ti
));
101 perr1
= SecAsn1DecodeData(coder
, derSrc
, twoIntsTemp
, &ti
);
103 perr2
= SecAsn1DecodeData(coder
, derSrc
, twoIntsTemp
, &ti
);
105 printf("***derDecodeTest: different errors (%d, %d)\n",
106 (int)perr1
, (int)perr2
);
111 printf("derDecodeTest: expect failure, got success\n");
117 printf("derDecodeTest: expect success, got %d\n", (int)perr1
);
121 SecAsn1CoderRelease(coder
);
125 printf("End of loop, CR to continue: ");