]>
git.saurik.com Git - apple/security.git/blob - SecurityTests/clxutils/clAppUtils/BlobList.cpp
1 /*** BlobList class for managing groups of raw certs and CRLs ***/
4 #include <utilLib/fileIo.h>
5 #include <utilLib/common.h>
9 #include <security_cdsa_utils/cuPem.h>
13 for(uint32 dex
=0; dex
<mNumBlobs
; dex
++) {
14 free(mBlobList
[dex
].Data
); // mallocd by readFile()
21 /* blob is mallocd & copied; its referent is not copied */
22 void BlobList::addBlob(const CSSM_DATA
&blob
, CSSM_BOOL copyBlob
/* = CSSM_FALSE */)
25 mBlobList
= (CSSM_DATA_PTR
)realloc(mBlobList
, mNumBlobs
* sizeof(CSSM_DATA
));
26 CSSM_DATA_PTR dst
= &mBlobList
[mNumBlobs
- 1];
28 /* can't use appCopyCssmData since we free with free(), not appFree() */
29 dst
->Length
= blob
.Length
;
30 dst
->Data
= (uint8
*)malloc(dst
->Length
);
31 memmove(dst
->Data
, blob
.Data
, dst
->Length
);
39 int BlobList::addFile(const char *fileName
,
40 const char *dirName
/* = NULL */)
46 unsigned char *blobData
;
49 int len
= strlen(dirName
) + strlen(fileName
) + 2;
50 fullName
= (char *)malloc(len
);
51 sprintf(fullName
, "%s/%s", dirName
, fileName
);
54 fullName
= (char *)fileName
;
56 rtn
= cspReadFile(fullName
, &blobData
, &blobDataLen
);
58 printf("***Error reading file %s\n", fullName
);
65 /* convert from PEM to DER if appropriate */
66 if(isPem(blobData
, blobDataLen
)) {
68 unsigned char *derData
;
70 if(pemDecode(blobData
, blobDataLen
, &derData
, &derDataLen
)) {
71 printf("***Error PEM-decoding file %s; using as raw data\n", fileName
);
73 blob
.Length
= blobDataLen
;
77 blob
.Length
= derDataLen
;
82 /* raw file data is the stuff we'll use */
84 blob
.Length
= blobDataLen
;