#include <security_cdsa_client/tpclient.h>
namespace Security {
namespace CssmClient {
TPImpl::TPImpl(const Guid &guid)
: AttachmentImpl(guid, CSSM_SERVICE_TP), mUseCL(NULL), mUseCSP(NULL),
mOwnCL(false), mOwnCSP(false)
{
}
TPImpl::TPImpl(const Module &module)
: AttachmentImpl(module, CSSM_SERVICE_TP), mUseCL(NULL), mUseCSP(NULL),
mOwnCL(false), mOwnCSP(false)
{
}
TPImpl::~TPImpl()
{
if (mOwnCL)
delete mUseCL;
if (mOwnCSP)
delete mUseCSP;
}
void TPImpl::certGroupVerify(const CertGroup &certGroup,
const TPVerifyContext &context,
TPVerifyResult *result)
{
setupCL();
setupCSP();
check(CSSM_TP_CertGroupVerify(handle(), (*mUseCL)->handle(), (*mUseCSP)->handle(),
&certGroup, &context, result));
}
void TPImpl::setupCL()
{
if (mUseCL == NULL) {
secdebug("tpclient", "TP is auto-attaching supporting CL");
mUseCL = new CL(gGuidAppleX509CL);
mOwnCL = true;
}
}
void TPImpl::setupCSP()
{
if (mUseCSP == NULL) {
secdebug("tpclient", "TP is auto-attaching supporting CSP");
mUseCSP = new CSP(gGuidAppleCSP);
mOwnCSP = true;
}
}
void TPImpl::use(CL &cl)
{
if (mOwnCL)
delete mUseCL;
mUseCL = &cl;
mOwnCL = false;
}
void TPImpl::use(CSP &csp)
{
if (mOwnCSP)
delete mUseCSP;
mUseCSP = &csp;
mOwnCSP = false;
}
CL &TPImpl::usedCL()
{
setupCL();
return *mUseCL;
}
CSP &TPImpl::usedCSP()
{
setupCSP();
return *mUseCSP;
}
TPBuildVerifyContext::TPBuildVerifyContext(CSSM_TP_ACTION action, Allocator &alloc)
: allocator(alloc)
{
clearPod();
mCallerAuth.clearPod();
mDlDbList.clearPod();
Action = action;
callerAuthPtr(&mCallerAuth);
mCallerAuth.dlDbList() = &mDlDbList;
}
} }