X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/80e2389990082500d76eb566d4946be3e786c3ef..d8f41ccd20de16f8ebe2ccc84d47bf1cb2b26bbb:/SecurityTests/clxutils/clAppUtils/BlobList.cpp diff --git a/SecurityTests/clxutils/clAppUtils/BlobList.cpp b/SecurityTests/clxutils/clAppUtils/BlobList.cpp new file mode 100644 index 00000000..53bd05b4 --- /dev/null +++ b/SecurityTests/clxutils/clAppUtils/BlobList.cpp @@ -0,0 +1,92 @@ +/*** BlobList class for managing groups of raw certs and CRLs ***/ + +#include "BlobList.h" +#include +#include +#include +#include +#include +#include + +BlobList::~BlobList() +{ + for(uint32 dex=0; dexLength = blob.Length; + dst->Data = (uint8 *)malloc(dst->Length); + memmove(dst->Data, blob.Data, dst->Length); + } + else { + *dst = blob; + } +} + + +int BlobList::addFile(const char *fileName, + const char *dirName /* = NULL */) +{ + CSSM_DATA blob; + int rtn; + char *fullName; + unsigned blobDataLen; + unsigned char *blobData; + + if(dirName) { + int len = strlen(dirName) + strlen(fileName) + 2; + fullName = (char *)malloc(len); + sprintf(fullName, "%s/%s", dirName, fileName); + } + else { + fullName = (char *)fileName; + } + rtn = cspReadFile(fullName, &blobData, &blobDataLen); + if(rtn) { + printf("***Error reading file %s\n", fullName); + if(dirName) { + free(fullName); + } + return rtn; + } + + /* convert from PEM to DER if appropriate */ + if(isPem(blobData, blobDataLen)) { + unsigned derDataLen; + unsigned char *derData; + + if(pemDecode(blobData, blobDataLen, &derData, &derDataLen)) { + printf("***Error PEM-decoding file %s; using as raw data\n", fileName); + blob.Data = blobData; + blob.Length = blobDataLen; + } + else { + blob.Data = derData; + blob.Length = derDataLen; + free(blobData); + } + } + else { + /* raw file data is the stuff we'll use */ + blob.Data = blobData; + blob.Length = blobDataLen; + } + addBlob(blob); + if(dirName) { + free(fullName); + } + return 0; +} +